问题描述
在许多情况下,我使用 @Parameterized
来运行多个排列的测试。这非常有效并且使测试代码本身变得简单和干净。
I use @Parameterized
in many cases to run tests on a number of permutations. This works very well and keeps the test-code itself simple and clean.
但有时我想让一些测试方法仍然只运行一次没有使用参数,JUnit是否有办法将测试方法标记为单例或运行一次?
However sometimes I would like to have some of the test-methods still run only once as they do not make use of the parameters, is there a way with JUnit to mark the test-method as "singleton" or "run-once"?
注意:这不是关注在Eclipse中运行单个测试,我知道如何做到这一点:)
Note: This does not concern running single tests in Eclipse, I know how to do that :)
推荐答案
您可以将任意数量的测试类关联起来运行一起使用套房。这样,所有测试都会在您测试课程时运行,并且您可以混合不同的测试跑步者。
You can associate any number of test classes to run together using a suite. This way all the tests are run when you test your class and you can mix different test runners.
- 创建与课程相关的测试套件您正在测试
- 添加对参数化测试类的引用
-
添加包含非参数化测试的其他类。
- Create a test suite associated with the class you are testing
- Add a reference to the parameterized test class
Add the other class(es) containing non parameterized tests.
import org.junit.runners.Suite;
import org.junit.runner.RunWith;
@RunWith(Suite.class)
@Suite.SuiteClasses({ParameterizedTestClass.class, UnitTests.class, MoreUnitTests.class})
public class SutTestSuite{
//Empty...
}
这篇关于当使用JUnit的@Parameterized时,我可以让一些测试仍然只运行一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!