我有两个 TestNG 运行程序来运行 cucumber 场景的主要和失败范围。如果 MainTestRunner 成功,Jenkins 构建状态为“成功”并且 FailedTestRunner 将不会在 rerun.txt 中找到任何失败的场景。但是如果 MainTestRunner 失败了场景并且它在 FailedTestRunner 的范围内重新运行并通过了,Jenkins 构建无论如何都会失败。

我需要一个解决方案来使构建状态“绿色”,因为所有测试最终都通过了。

我的测试运行器没有特别的技巧:

MainTestRunner:

@CucumberOptions(
        features = ".",
        glue = {"steps"},
        monochrome = true,
        format = {
                "pretty",
                "html:target/cucumber-pretty",
                "json:target/CucumberTestReport.json",
                "rerun:target/rerun.txt"
        })

public class MainTestRunner extends AbstractTestNGCucumberTests {
private TestNGCucumberRunner testNGCucumberRunner;

@BeforeClass(alwaysRun = true)
public void setUpClass() {
    testNGCucumberRunner = new TestNGCucumberRunner(this.getClass());
}

@Test(description = "Runs Cucumber Feature", dataProvider = "features")
public void feature(CucumberFeatureWrapper cucumberFeature) {
    testNGCucumberRunner.runCucumber(cucumberFeature.getCucumberFeature());
}

@DataProvider
public Object[][] features() {
    return testNGCucumberRunner.provideFeatures();
}

@AfterClass(alwaysRun = true)
public void tearDownClass() {
    testNGCucumberRunner.finish();
}
}

失败的TestRunner:
@CucumberOptions(
    features = "@target/rerun.txt"
    , glue = {"steps"}
    , monochrome = true
    , format = {
    "pretty",
    "html:target/cucumber-pretty",
    "json:target/CucumberTestReport.json",
    "rerun:target/rerun.txt"
})

public class FailedTestRunner extends AbstractTestNGCucumberTests {}

最佳答案

如果我能看到您的管道步骤,这将有助于回答,但是如果您通过 sh 步骤执行 cucumber 测试,那么您可以使用 returnStatus:true 获得执行的退出状态。如果 main 失败并且 sh 返回 exit status > 0 那么您可以在不更改构建状态的情况下运行失败。如果重播失败,那么你让它返回失败状态,如果主要通过,那么你可以跳过失败。

关于java - 如果成功重新运行失败的场景,如何更改 Jenkins 构建状态,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/54090819/

10-14 12:22
查看更多