method dependency in testng.xml

笑着哭i 提交于 2021-02-20 03:36:32

问题


I am trying to add method dependency in testng.xml, but this does not seem to work. could someone suggest, what am i missing here.

<suite name="Test Suite for End To End">
	<test name="AUT_E2E_01">
		<parameter name="browser" value="Chrome" />
		<classes>
			<class name="com.myunit.regressiontests">
				<methods>
					<include name="AutTC03" />
					<include name="AutTC11" dependsOnMethods="AutTC03" />
				</methods>
			</class>
		</classes>
	</test>
</suite>

回答1:


Attribute dependsOnMethods is not allowed there (see TestNG DTD).

Here are some excerpts from TestNG Documentation - 5.7 - Dependencies (links added for convenience):

TestNG allows you to specify dependencies either with annotations or in XML.

5.7.1 - Dependencies with annotations

You can use the attributes dependsOnMethods or dependsOnGroups, found on the @Test annotation.

5.7.2 - Dependencies in XML

Alternatively, you can specify your group dependencies in the testng.xml file.

i.e. You can define "group" dependencies in both Java and in XML but you can only define "method" dependencies in Java (using the @Test annotation).

However, even though you cannot define "method" dependencies in XML you can place your methods in groups to use instead.

e.g. The following assumes that you have placed AutTC03 and AutTC11 into test groups named AutTC03-Group and AutTC11-Group respectively:

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Test Suite for End To End">
    <test name="AUT_E2E_01">
        <parameter name="browser" value="Chrome" />
        <classes>
            <class name="com.myunit.regressiontests">
                <methods>
                    <include name="AutTC03" />
                    <include name="AutTC11" dependsOnMethods="AutTC03" />
                </methods>
            </class>
        </classes>
        <groups>
            <dependencies>
                <group name="AutTC11-Group" depends-on="AutTC03-Group" />
            </dependencies>
        </groups>
    </test>
</suite>


来源:https://stackoverflow.com/questions/34713608/method-dependency-in-testng-xml

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!