【问题标题】:How to create multiple test suites like cucumber-jvm/examples/java-calculator-testng如何创建多个测试套件,如 cucumber-jvm/examples/java-calculator-testng
【发布时间】:2014-06-18 22:11:28
【问题描述】:

我克隆了 cucumber-jvm 项目并运行了示例 java-calculator-testng。生成的 testNg 报告显示两个测试套件。

第一个套件名为“cucumber.examples.java.calculator.RunCukesTest”,包含一个名为“run_cukes”的测试。

第二个套件名为“cucumber.examples.java.calculator.RunCukesByCompositionTest”,包含一个名为“runCukes”的测试。

我想在我自己的项目中复制它。我的意思是我想要一个显示两个测试套件的 testNg 报告。一个继承自 AbstractTestNGCucumberTests 的测试套件和另一个不继承的测试套件。

我创建的项目具有与 java-calculator-testng 示例相同的依赖项和文件结构。我还将我的类放在同一个包中,如 java-calculator-example。

问题是我的 testNg 报告只显示了一个名为“命令行套件”的测试套件,其中包含一个名为“命令行测试”的测试,该测试有两个类。

为什么我的测试类被合并到同一个测试套件中,而不是像示例中那样单独的套件?

另外,为什么我的测试套件命名为“命令行套件”

这是我尝试复制 java-calculator-testng 示例的方式:

RunCukesTest.java

// RunCukesTest.java
import cucumber.api.CucumberOptions;
import cucumber.api.testng.AbstractTestNGCucumberTests;
@CucumberOptions(format = "json:target/cucumber-report.json")
public class RunCukesTest extends AbstractTestNGCucumberTests {
}

RunCukesByCompositionTest.java

// RunCukesByCompositionTest.java
import cucumber.api.CucumberOptions;
import cucumber.api.testng.TestNGCucumberRunner;
import org.testng.annotations.Test;
@CucumberOptions(format = "json:target/cucumber-report-composite.json")
public class RunCukesByCompositionTest extends RunCukesByCompositionBase {

    @Test(groups = "examples-testng", description = "Example of using TestNGCucumberRunner to invoke Cucumber")
    public void runCukes() {
        new TestNGCucumberRunner(getClass()).runCukes();
    }
}

RunCukesByCompositionBase.java

// RunCukesByCompositionBase
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;

class RunCukesByCompositionBase {

    @BeforeClass
    public void beforeClass() {
        // do expensive setup
        System.out.println("[Base] @BeforeClass");
    }

    @BeforeMethod
    public void beforeMethod() {
        // do expensive setup
        System.out.println("[Base] @BeforeMethod");
    }
}

【问题讨论】:

    标签: cucumber testng cucumber-jvm


    【解决方案1】:

    我想出了如何在一份 testNg 报告中创建两个测试套件。我仍然不确定 java-calculator-testng 示例是如何实现这一点的,但我将分享我学到的知识,以防它对其他人有所帮助。

    测试套件在 pom.xml 文件中的 surefire 插件中配置。

    <configuration>      
       <suiteXmlFiles>
           <suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
           <suiteXmlFile>src/test/resources/testsuitetwo.xml</suiteXmlFile>
       </suiteXmlFiles>
    <configuration>
    

    在测试套件 xml 文件中,您可以指定套件名称和测试名称。

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
    <suite name="Test Suite 1" verbose="1" configfailurepolicy="continue" >
        <test name="FooTest 1.a">
            <classes>
                <class name="com.turkeysandwitch.testsuites.RunCukesTest" />
            </classes>
        </test>
        <test name="FooTest 1.b" >
            <classes>
                <class name="com.turkeysandwitch.testsuites.RunCukesByCompositionTest"/>
            </classes>
        </test>
    </suite>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-02-20
      • 2011-12-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-09
      • 2020-12-17
      • 2017-01-09
      相关资源
      最近更新 更多