具有多个类的 TestNG 中的优先级 [英] Priority in TestNG with multiple classes

查看:23
本文介绍了具有多个类的 TestNG 中的优先级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我面临以下问题:我创建了两个类,其中包括具有优先级属性的@Tests:

I'm facing with the following problem: I created two classes which include @Tests with priority attribute:

@Test( priority = 1 )
public void testA1() {
    System.out.println("testA1");
}

@Test( priority = 2 )
public void testA2() {
    System.out.println("testA2");
}

@Test( priority = 3 )
public void testA3() {
    System.out.println("testA3");
}

...和...

@Test( priority = 1 )
public void testB1() {
    System.out.println("testB1");
}

@Test( priority = 2 )
public void testB2() {
    System.out.println("testB2");
}

@Test( priority = 3 )
public void testB3() {
    System.out.println("testB3");
}

我将两个类都放在 testng.xml 中的一个测试中,但是当我运行测试时,它会根据两个类的优先级对我的 @Tests 进行排序:

I put both classes under one test in testng.xml but when I run the test, it will order my @Tests based on the priorities from both classes:

testA1
testB1
testA2
testB2
testA3
testB3

我期待以下结果:

testA1
testA2
testA3
testB1
testB2
testB3

我的问题是,如何防止基于两个类对 @Tests 进行排序并同时仅从一个类运行 @Tests?

My question is that how can I prevent to order my @Tests based on both classes and run @Tests only from one class at the same time?

推荐答案

在你的套件 xml 中使用 group-by-instances="true"

In your suite xml use group-by-instances="true"

示例,其中 TestClass1 和 TestClass2 与您的内容相同

Sample, where TestClass1 and TestClass2 has the same content as yours

<suite thread-count="2" verbose="10" name="testSuite" parallel="tests">
<test verbose="2" name="MytestCase" group-by-instances="true">
    <classes>
        <class name="com.crazytests.dataproviderissue.TestClass1" />
        <class name="com.crazytests.dataproviderissue.TestClass2" />
    </classes>
</test>
</suite> 

我得到输出

testA1

testA2

testA3

testB1

testB2

testB3

这篇关于具有多个类的 TestNG 中的优先级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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