testng.xml 中的方法依赖 [英] method dependency in testng.xml

查看:38
本文介绍了testng.xml 中的方法依赖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 testng.xml 中添加方法依赖项,但这似乎不起作用.有人可以建议,我在这里错过了什么.

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>

推荐答案

dependsOnMethods 属性在那里是不允许的(参见 TestNG DTD).

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

以下是 TestNG 文档 - 5.7 - 依赖项的一些摘录(为方便起见添加了链接):

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

TestNG 允许您使用注释或 XML 指定依赖项.

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

5.7.1 - 带注释的依赖

您可以使用属性 dependsOnMethodsdependsOnGroups,在 @Test 上找到 注释.

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

5.7.2 - XML 中的依赖关系

或者,您可以在 testng 中指定您的组依赖项.xml 文件.

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

即您可以定义组"Java 和 XML 中的依赖项,但您只能定义方法";Java 中的依赖项(使用 @Test 注释).

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).

然而,即使您无法定义方法"XML 中的依赖项,您可以将方法分组以供使用.

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

例如以下假设您已将 AutTC03AutTC11 放入 测试组分别命名为AutTC03-GroupAutTC11-Group:

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>

这篇关于testng.xml 中的方法依赖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆