Does JUnit 3 have something analogous to @Ignore

爷,独闯天下 提交于 2019-12-08 14:29:54

问题


I'm forced to use JUnit 3. If I were using JUnit 4, I would occasionally use @Ignore since several of my tests take a bit of time.

Is there anything analogous in JUnit 4? Commenting out tests is sloppy, and changing the name (from testXxx()) could lead to forgotten tests. @Ignore is great, because it always reminds you which tests were not run.

Does anyone have a best practice for running some of a test classes methods in JUnit 3?


回答1:


I don't know any other solution apart from commenting out tests or renaming them. I would go for the renaming option and use my own convention. For example all of them will start with ignoreXXX(). Then you can do one find/replace with your editor and you are ready.




回答2:


In order to conditionally ignore tests in Robotium / JUnit 3, I override runTest() like

@Override
protected void runTest() throws Throwable {
    // Do nothing if the precondition does not hold.
    if (precondition) {
        super.runTest();
    }
}

Tests which are ignored this way will show up as "Success" in Eclipse, but as there is no "Ignored" state with JUnit 3, this is the best I was able to get.




回答3:


you can prepend the method with failing, so all methods like failingtest***() will be ignored during the junit run.



来源:https://stackoverflow.com/questions/3061650/does-junit-3-have-something-analogous-to-ignore

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!