在团队合作中覆盖或汇总测试结果

我有团队合作的工作,分2个步骤:
1.执行测试。
2.重新运行失败。

我们在第1步中有3个测试失败,并且在重新运行后只有1个测试失败。

Teamcity生成的报告具有4个失败的测试而不是1个。如何通过合格状态覆盖第1步的失败测试结果?

编辑

例如,我的套房看起来像这样:

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Suite 1" thread-count="5" parallel="methods">
    <test name="Test 1">
        <classes>
            <class name="unittest.TestNGTest"/>
        </classes>
    </test>
</suite>

Java代码:



import org.testng.Assert;
import org.testng.IRetryAnalyzer;
import org.testng.ITestResult;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

public class TestNGTest {


    @AfterMethod
    public void afterMethod() {
        System.out.println(Thread.currentThread().getId() + " afterMethod");
    }

    @BeforeMethod
    public void beforeMethod() {
        System.out.println(Thread.currentThread().getId() + " beforeMethod");
    }

    @DataProvider
    public Object[][] dp1() {
        return new Object[][]{
                {1},{2}
        };
    }

    @Test(dataProvider = "dp1")
    public void testM1(int param) {
        Assert.assertTrue(param > 3);
    }

    @DataProvider
    public Object[][] dp2() {
        return new Object[][]{
                {1},{2},{3},{4},{5},{6},{7}
        };
    }

    @Test(dataProvider = "dp2")
    public void testM2(int param) {
        Assert.assertFalse(param == 7);
    }

}

运行后,我的代码生成了重新运行测试套件,teamcity在第二步中运行了该套件:

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Suite 1" thread-count="1" parallel="methods">
    <test name="Test 1">
    <parameter name="indicies" value = "0:1"/> <-- that means that i want rerun only first and second dataprovider configuration -->
        <classes>
            <class name="unittest.TestNGTest">
            <include name = testM1/>
    </class>
        </classes>
    </test>
    <test name="Test 2">
<parameter name="indicies" value = "6"/> <-- that means that i want rerun only seventh dataprovider configuration -->
        <classes>
            <class name="unittest.TestNGTest">
                <include name = testM2/>  
             </class>
        </classes>
    </test>
</suite>

如您所见,我仅在一个线程中使用相应的dataprovider配置重新运行失败的测试用例

anothermimi 回答:在团队合作中覆盖或汇总测试结果

有三种解决方法。

  1. 如果您使用的是Cucumber Framework,那么我建议您 您使用ExtendedCucumberRunner内置支持 重新运行失败的测试而不增加测试数量,您将 不需要分别重新运行失败的测试用例
  2. 如果您使用的是TestNG框架,请实施IRetry接口以重试 在同一运行中失败的测试用例。
  3. 或者作为最后的手段,分析结果并排除自己的重复测试

编辑:

  

因此,如果我重新运行我的案子,则将重新运行所有50种配置

不是。只有那些在这些配置中失败的数据点才会运行。

  

我只想重新运行失败的dataprovider集(并非在每种情况下都重新运行)   在1个线程中。

您可以在实现IRetry接口时进行控制。因此,我要求分享一些最低限度的可重复代码以演示您的问题。

  

我创建了解析器,该解析器为我创建了必要的新xml套件   来自dataprovider的索引,我可以在1个线程中运行。

我建议您考虑以编程方式运行TestNG测试。

正如您所说的,您有大量需要运行的测试,但并非全部都需要重试逻辑,我建议您将一个需要重试逻辑的组件合并到一个套件中,然后在另一个套件中休息,然后将IRetry侦听器添加到重试套件。

就并行执行而言,重试逻辑将遵循与常规测试相同的路径,因此,如果您在1个线程中运行,则在多个线程中运行,它将在单线程中运行,然后它将并行运行。基本上,重试逻辑是在每个测试方法实例之后调用的。

编辑2:

TestNG.xml文件:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Suite 1" data-provider-thread-count="10" parallel="methods">
    <test name="Test 1">
        <classes>
            <class name="unittest.TestNGTest"/>
        </classes>
    </test>
</suite>

测试类:

package unittest;


import org.testng.Assert;
import org.testng.IRetryAnalyzer;
import org.testng.ITestResult;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

public class TestNGTest {

    public static class IRetryImplementation implements IRetryAnalyzer {
        private int retries = 3;

        @Override
        public boolean retry(ITestResult result) {
            return (retries--) > 0 && !result.isSuccess();
        }
    }

    @AfterMethod
    public void afterMethod() {
        System.out.println(Thread.currentThread().getId() + " afterMethod");
    }

    @BeforeMethod
    public void beforeMethod() {
        System.out.println(Thread.currentThread().getId() + " beforeMethod");
    }

    @DataProvider(parallel = true)
    public Object[][] dp1() {
        return new Object[][]{
                {1},{2}
        };
    }

    @Test(dataProvider = "dp1",retryAnalyzer = IRetryImplementation.class)
    public void testM1(int param) {
        System.out.println(Thread.currentThread().getId() + " test 1");
        Assert.assertTrue(param > 1);
    }

    @DataProvider(parallel = true)
    public Object[][] dp2() {
        return new Object[][]{
                {1},{2}
        };
    }

    @Test(dataProvider = "dp2",retryAnalyzer = IRetryImplementation.class)
    public void testM2(int param) {
        System.out.println(Thread.currentThread().getId() + " test 2");
        Assert.assertTrue(param > 1);
    }

}

输出:

15 beforeMethod
16 beforeMethod
16 test 2
18 beforeMethod
18 test 2
17 beforeMethod
Test ignored.
16 afterMethod
16 beforeMethod
16 test 2
Test ignored.
16 afterMethod
16 beforeMethod
16 test 2
Test ignored.
16 afterMethod
16 beforeMethod
16 test 2
16 afterMethod
15 test 1
Test ignored.
17 test 1
17 afterMethod
15 afterMethod
15 beforeMethod
18 afterMethod
15 test 1
Test ignored.
15 afterMethod
15 beforeMethod
15 test 1
Test ignored.
15 afterMethod
15 beforeMethod
15 test 1
15 afterMethod

我创建了一个最小的代码来演示重试的工作方式。如该代码所示,失败的数据点在与产生原始测试方法并提供数据点的线程相同的线程中运行。此外,如您所见,它还会重试运行失败的方法,从而重新运行配置方法。

本文链接:https://www.f2er.com/3058719.html

大家都在问