问题描述
我有一个具有以下结构的测试套件
I am having a test suite which is having the following structure
TestClass1
- testmethod1()
- testmethod2()
- testmethod3()
- testmethod4()
TestClass2
- testmethod11()
- testmethod22()
- testmethod33()
- testmethod44()
在上面的结构中,我想执行testmethod4()作为最后一个.即)最后执行.有一个@FixMethodOrder注释,它按顺序执行方法而不是testclass.是否有任何机制可以同时维护测试类和测试方法中的顺序.借助@FixMethodOrder,我可以通过重命名测试方法的名称来执行该方法,但是我无法指示junit将测试类作为最后一个(最后一个)执行.
In the above structure i want to execute the testmethod4() as the final one. ie) executed at last.There is a annotation @FixMethodOrder which executes a method in order not the testclass. Is there any mechanism to maintain order in test class and testmethod together. With the @FixMethodOrder i can execute the method by renaming the name of the test method but i can't instruct junit to execute the test class as the final one(last one).
推荐答案
尽管再次引用@Andy-
Though quoting @Andy again -
但是,如果需要这样做,您可以尝试 Suite
But if the need be to do so, you can try out Suite
@RunWith(Suite.class)
@Suite.SuiteClasses({
TestClass2.class,
TestClass1.class
})
public class JunitSuiteTest {
}
您可以在其中指定
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class TestClass1 {
@AfterClass
public void testMethod4() {
,然后小心地命名您的方法testMethod4
,使其在末尾执行,或者您也可以使用 @AfterClass
,很快就会被 @AfterAll
.
and then take care to name your method testMethod4
as such to be executed at the end OR you can also use @AfterClass
which could soon be replaced by @AfterAll
in Junit5.
这篇关于在junit中执行测试套件的订单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!