问题描述
当我使用命令行和testng.xml文件中定义的测试运行我的testng测试时,它们按照它们在testng.xml中指定的顺序运行
< suite name =WorkDepot Tests>
< test name =提交工作成果测试>
< classes>
< class name =workdepot.test.SubmitWorkTest/>
< class name =workdepot.test.WorkResultTest/>
< class name =workdepot.test.SubmitWorkTest/>
< class name =workdepot.test.WorkErrorTest/>
< class name =workdepot.test.SubmitWorkTest/>
< class name =workdepot.test.MultipleHasTest/>
< class name =workdepot.test.WorkResultTest/>
< class name =workdepot.test.CallbackTest/>
< class name =workdepot.test.NegCallBackTest/>
< class name =workdepot.test.NegSubmitWork/>
< class name =workdepot.test.NegGetWork/>
< class name =workdepot.test.NegHasWork/>
< class name =workdepot.test.NegSubmitResult/>
< class name =workdepot.test.NegSubmitError/>
< class name =workdepot.test.NegReadResult/>
< class name =workdepot.test.NegMultipleHas/>
< / classes>
< / test>
< / suite>
现在我想使用gradle Test
任务类型,并使用 include
模式。但是执行顺序现在改变了(任意的)。
task integTest(type:Test){
useTestNG()
testClassDir = file(build /类/ integTest)
包含workdepot / test / SubmitWorkTest *
包含workdepot / test / WorkResultTest *
包含workdepot / test / SubmitWorkTest *
包含workdepot / test / WorkErrorTest *
包含workdepot / test / SubmitWorkTest *
包含workdepot / test / MultipleHasTest *
包含workdepot / test / WorkResultTest *
包含workdepot / test / CallbackTest *
包含workdepot / test / NegCallBackTest *
包含workdepot / test / NegSubmitWork *
包含workdepot / test / NegGetWork *
包含workdepot / test / NegHasWork *
包含workdepot / test / NegSubmitResult *
包含workdepot / test / NegSubmitError *
包含workdepot / test / NegReadResult *
includeworkdepot / test / NegMultipleHas *
}
我如何确保tes ts是按照testng.xml中的顺序运行的,而不会改变测试代码(即添加测试之间的依赖关系)。
它不能从gradle级别为 JUnit 和 TestNG 进行控制。正如你所提到的,测试源可以被修改。对于 JUnit ,可以定义测试套件以获得对测试执行顺序的控制权。如果 TestNG 具有与此类测试套件相同的功能,那么它可能就是要走的路。
When I run my testng tests using command line and with tests defined in a testng.xml file, they run in the order they are specified in the testng.xml
<suite name="WorkDepot Tests">
<test name="Submit work-result test">
<classes>
<class name="workdepot.test.SubmitWorkTest"/>
<class name="workdepot.test.WorkResultTest"/>
<class name="workdepot.test.SubmitWorkTest"/>
<class name="workdepot.test.WorkErrorTest"/>
<class name="workdepot.test.SubmitWorkTest"/>
<class name="workdepot.test.MultipleHasTest"/>
<class name="workdepot.test.WorkResultTest"/>
<class name="workdepot.test.CallbackTest"/>
<class name="workdepot.test.NegCallBackTest"/>
<class name="workdepot.test.NegSubmitWork"/>
<class name="workdepot.test.NegGetWork"/>
<class name="workdepot.test.NegHasWork"/>
<class name="workdepot.test.NegSubmitResult"/>
<class name="workdepot.test.NegSubmitError"/>
<class name="workdepot.test.NegReadResult"/>
<class name="workdepot.test.NegMultipleHas"/>
</classes>
</test>
</suite>
Now I want to run those using the gradle Test
task type and I use include
pattern for the same. But the order of execution is now changed (arbitrary).
task integTest(type: Test){
useTestNG()
testClassDir = file("build/classes/integTest")
include "workdepot/test/SubmitWorkTest*"
include "workdepot/test/WorkResultTest*"
include "workdepot/test/SubmitWorkTest*"
include "workdepot/test/WorkErrorTest*"
include "workdepot/test/SubmitWorkTest*"
include "workdepot/test/MultipleHasTest*"
include "workdepot/test/WorkResultTest*"
include "workdepot/test/CallbackTest*"
include "workdepot/test/NegCallBackTest*"
include "workdepot/test/NegSubmitWork*"
include "workdepot/test/NegGetWork*"
include "workdepot/test/NegHasWork*"
include "workdepot/test/NegSubmitResult*"
include "workdepot/test/NegSubmitError*"
include "workdepot/test/NegReadResult*"
include "workdepot/test/NegMultipleHas*"
}
How can I ensure the tests are run in the order as in the testng.xml without changing the test code (i.e., adding dependencies between tests)
It cannot be controlled from gradle level both for JUnit and TestNG. As you mentioned test sources can be modified. For JUnit a test suite can be defined to gain control over test execution order. If TestNG has it's equivalent of such test suite it may be the way to go.
这篇关于测试任务执行顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!