【问题标题】:How to order test cases using priority and groups annotation?如何使用优先级和组注释对测试用例进行排序?
【发布时间】:2015-08-24 10:42:16
【问题描述】:

我想通过自动化测试一些流程。我正在使用 selenium、maven、java 和 testNG。我有 2 个不同的班级。比如说A类和B类。

 public class A (){
    @Test(groups="flow1",priority=0)
    public void method a1()
    {
    }
    @Test(groups="flow1".priority=2)
    public void method a2()
    {
    }
    @Test
    public void method a3()
    {
    }

第二类是B类

 public class b (){
    @Test(groups="flow1", priority=1)
    public void method b1()
    {
    }
    @Test
    public void method b2()
    {
    }
    @Test
    public void method b3()
    {
    } 

现在我想实现如下所示的流程

method a1()
method b1()
method a2()

我曾通过 testng.xml 尝试过这种方式

 <test name="test1">
    <groups>
    <run>
    <include name="flow1" />
    </run>
    </groups>
    <classes>
    <class name="a" />
    <class name="b" />
    </classes>
    </test>

但我没有得到那个输出。它只会运行一个测试用例,然后跳过其他用例。 我也尝试了一些不同的方式,但我没有达到我的目标。 谁能帮帮我

谢谢

【问题讨论】:

  • @Smajl 我想通过使用组和优先级的 testNG 注释来实现它。而且也没有满足我的情况的参数。
  • 我认为使用 maven 无法做到这一点。唯一接近您尝试做的事情是使用 Surefire 插件和该 SO 答案中的解决方法。
  • 但它会按字母顺序运行测试用例。而且我的测试用例名称不是按字母顺序排列的。有什么办法吗
  • 我不认为有办法做到这一点,但如果我错了,我会很好奇。无论如何,有依赖测试不是一个好习惯。顺序通常不重要。

标签: java maven selenium-webdriver testng


【解决方案1】:

在你的 testng.xml 中添加 group-by-instances="true"

<suite thread-count="2" verbose="10" name="testSuite" parallel="tests">
<test verbose="2" name="MytestCase" group-by-instances="true">
    <classes>
        <class name="com.A.classA" />
        <class name="com.A.classB" />
    </classes>
</test>
</suite> 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-06
    • 2021-04-14
    • 2016-09-13
    • 1970-01-01
    • 1970-01-01
    • 2018-10-16
    相关资源
    最近更新 更多