JUnit Test Runner 在运行测试之前创建测试

发布于 2024-07-30 06:01:05 字数 144 浏览 5 评论 0原文

我使用 JUnit 3.x TestRunner 在运行所有测试之前立即实例化它们。

是否有一个测试运行程序可以在运行每个测试(或至少每个测试套件的测试)之前创建它们?
我可以使用 JUnit 4.x 运行程序,但我的测试是 3.x 测试。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

孤千羽 2024-08-06 06:01:06

在 JUnit 3 中,您需要编写自己的 TestSuite 类来延迟套件中测试的实例化。

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

壹場煙雨 2024-08-06 06:01:06

你可能做错了。

每个单元测试应该是独立的,不依赖于任何其他测试结果。
否则,当其中一个测试失败时,它将破坏依赖于它的所有测试。 因此,您会看到很多错误,但没有简单的方法来了解实际原因。 另一方面,如果所有单元测试都是独立的,则损坏的测试非常容易调试和修复。

编辑:我假设您问原始问题的原因是因为您的测试中有一些依赖项。 如果我错了请忽略这个答案:)

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 :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文