开发者

@BeforeClass still running the method everytime any test is run

I am using the @BeforeClass annotation to ensure that a set of activities are done just once in a set of 5-6 tests. There is a hierarch of 3 java files.

File1 extends TestCase

File2 extends File 1 (this is where i have to put the beforeclass annotation at the setUp method)

File3 extends File2 (File 3 has the tests.. 5 in number, but i want the set开发者_JAVA百科up in file 2 to be run just once)

Right now, the setUp method in File 2 is being called before every test in File3. even after putting the @BeforeClass annotation. What can i do to ensure that this setup runs only once for all the tests in File 3


I suspect that you're using a JUnit 3 TestRunner, which ignores annotations and uses only naming conventions (where setUp() is conventionally run before every test). Try having a method with the @Test annotation but not starting with "test" - if it's not run, you're using the JUnit 3 TestRunner.

So, to fix this, use the JUnit 4 TestRunner to start the test suite.


Since you are extending TestCase class, so setUp method is getting called before start of every test. For junit 4 onwards, you don't need to extend TestCase class. Just try to remove it and it should work. You will also need to add @Test annotation on test method

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜