gradle测试任务执行测试顺序

时间:2015-01-28 05:53:31

标签: gradle testng

当我使用命令行和testng.xml文件中定义的测试运行我的testng测试时,它们按照在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>

现在我想使用gradle Test任务类型运行那些,并且我使用include模式。但现在执行的顺序已经改变(任意)。

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*"

}

如何在不更改测试代码的情况下确保测试按照testng.xml中的顺序运行(即在测试之间添加依赖关系)

2 个答案:

答案 0 :(得分:1)

无法从gradle级别控制 JUnit TestNG 。正如您所提到的,可以修改测试源。对于 JUnit ,可以定义测试套件以控制测试执行顺序。如果 TestNG 具有相当于此类测试套件的可能性,那么可能就是这样。

答案 1 :(得分:1)

默认情况下,TestNG将按照XML文件中的测试顺序运行测试。否则,gradle测试将不保证任何订单,

你可以在运行之前拦截这些方法,但在这种情况下没有用