在 testNg 中排除测试 [英] Exclude Test in testNg

查看:39
本文介绍了在 testNg 中排除测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下 testNg XML 文件.我想运行 Test1 而不是 Test2.我该怎么做?我尝试使用排除"关键字排除 Test2 的方法.但这似乎行不通.我无法更改实际代码.不幸的是,这是被禁止的.我所能做的就是更改此 XML 并运行测试.有什么方法可以在仍然设法运行Test1的同时忽略Test2?我正在寻找一种比注释代码更优雅的方式.

I have the following testNg XML file. I would like to run Test1 and not Test2. How can I do it? I tried excluding the methods of Test2 using the "exclude" keyword. But it doesn't seem to work that. I cannot make changes to the actual code. Unfortunately, that is forbidden. All I can do is make changes to this XML and run the tests. Is there any way using which I can ignore Test2 while still manage to run Test1? I am looking for a more elegant way than commenting the code out.

<?xml version="1.0" encoding="UTF-8"?>
<suite name="Suite" parallel="false">
<parameter name="xxx" value="yyy" />
<parameter name="zzz" value="aaa" />
<parameter name="user" value="1" />

<test name="Test1">
    <parameter name="browser" value="Chrome" />
    <define name = "regression">
            <include name = "spot" />
            <include name = "sanity" />
        </define>
    <groups>
        <run>
            <include name="regression" />
        </run>
    </groups>
        <classes>
            <class name="class2" />
            <method>
                <include name="method1" />
                <include name="method2" />
            </method> 
        </classes>
</test>

<test name="Test2">
    <parameter name="browser" value="Firefox" />
        <define name = "regression">
            <include name = "spot" />
            <include name = "sanity" />
        </define>
    <groups>
        <run>
            <include name="spot" />
            <exclude name="sanity" />
        </run>
    </groups>
        <classes>
            <class name="class2" />
            <method>
                <include name="method1" />
                <include name="method2" />
            </method> 
        </classes>
</test>



</suite>  <!-- Suite -->

推荐答案

在 test2 中替换 include 以排除所有字段

In test2 replace include to exclude in all fields

通过这样做,您将从代码中排除该字段或方法

by doing this you will exclude that fields or methods from your code

这篇关于在 testNg 中排除测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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