本文介绍了保留顺序设置为 true 不会按照定义的组依赖项的顺序运行 TestNG 测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试运行分组 TestNG 测试.给定的 xml 是 testng.xml 中的一个测试:

I am trying to run grouped TestNG tests. The given xml is a test in testng.xml:

<test name="demo test" preserve-order="true">
       <groups>
         <run>
           <include name="openlogin"/>
           <include name="login"/>
           <include name="searchPatient"/>
           <include name="scheduleBySearch" />
           <include name="openDashboardFromPatientToday"/>
           <include name="openPatientChart"/>
           <include name="referralSearch"/>
           <include name="referralNotes"/>
           <include name="removeReferral"/>
           <include name="nonExistingReferralSearch"/>
         </run>

         <dependencies>
            <group name="removeReferral" depends-on="referralNotes"/>
            <group name="referralNotes" depends-on="referralSearch"/>
            <group name="referralSearch" depends-on="openPatientChart"/>
            <group name="openPatientChart" depends-on="openDashboardFromPatientToday"/>
            <group name="openDashboardFromPatientToday" depends-on="scheduleBySearch"/>
            <group name="scheduleBySearch" depends-on="searchPatient" />
            <group name="searchPatient" depends-on="login" />
            <group name="login" depends-on="openlogin"/>
         </dependencies>
        </groups>

        <classes>
         <class name="xtr.webaut.sanitytests.LoginTests"/>
         <class name="xtr.webaut.sanitytests.PatientSearchTest"/>
         <class name="xtr.webaut.sanitytests.PatientScheduleTests"/>
         <class name="xtr.webaut.sanitytests.PatientTodayTests"/>
         <class name="xtr.webaut.sanitytests.PatientDashboardViewTests"/>
         <class name="xtr.webaut.sanitytests.PatientChartReferralTests"/>
        </classes>
    </test>


这里有一个组nonExistingReferralSearch",我不想依赖于任何其他组.但我希望它以指定的顺序执行,并且我已将 <test> 的preserve-order"设置为 true.执行时,我发现TestNG没有按顺序执行非依赖组.它在组openlogin"之后立即执行该组,而我希望它最终被执行.

定义依赖并告诉TestNG维护执行顺序是错误的吗?是否定义了一个未知的优先级,TestNG 将首先执行任何非依赖测试/组,然后执行依赖测试?我希望它不是那么不灵活.

即使对于<test>中的通用场景,是否也无法按顺序运行一些没有任何依赖关系的测试方法/组和一些有依赖关系的测试方法/组强>?


Here there is a group "nonExistingReferralSearch" that I don't want to be dependent upon any other group. But I want it to be executed in the specified order and I have set "preserve-order" as true for the <test>. While execution, I find that TestNG does not execute the non-dependent group in order. It executes that group immediately after the group "openlogin" whereas I am expecting it to get executed in the end.

Is it wrong to define dependencies as well as tell TestNG to maintain an order of execution? Is there an unknown priority defined that TestNG will execute any non-dependent tests/groups first and then the dependent tests? I hope it is not that inflexible.

Even for a generic scenario in a <test>, is it not possible to run some test methods/groups without any dependency and some test methods/groups with dependencies, in an order?

推荐答案

我在套件中添加了preserve-order 参数.测试按照我们指定的顺序运行.

I added the preserve-order parameter in the suite. The tests run in the order we specified.

<suite name="Suite" preserve-order="true">

这篇关于保留顺序设置为 true 不会按照定义的组依赖项的顺序运行 TestNG 测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 18:13