JUnit Test Runner that creates tests just before running them

不打扰是莪最后的温柔 提交于 2019-12-10 19:20:18

问题


I use JUnit 3.x TestRunner that intantiates all tests at once before running them.

Is there a Test Runner available that would create each test (or at least each test suite's tests) just before running them?
I can use JUnit 4.x runners but my tests are 3.x tests.


回答1:


In JUnit 3 you'd need to write your own TestSuite class that delayed instantiation of the tests in the suite.




回答2:


You are probably doing it wrong.

Each unit test should be self-contained and not depend on any other test results. Otherwise when one of the tests break it will break all the tests that depend on it. So you will see a lot of errors without easy way to understand what is the actual cause. On the other hand if all unit tests are independent a broken test is extremely easy to debug and fix.

EDIT: I am assuming the reason you ask the original question is because you have some dependencies in your test. If I am wrong please ignore this answer :)



来源:https://stackoverflow.com/questions/1191995/junit-test-runner-that-creates-tests-just-before-running-them

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