微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

QAF黄瓜testNG带弹簧靴

如何解决QAF黄瓜testNG带弹簧靴

我有一个使用Spring Boot和Testng的黄瓜项目。

这是校长班

@SpringBoottest
public class CucumberTestDeFinitions extends FunctionalTesting {

    @Given("Something")
    public void smthg(){

    }
}
@ExtendWith(SpringExtension.class)
@ContextConfiguration(classes = FunctionalTestingApp.class,initializers =
        ConfigFileApplicationContextinitializer.class)
public class FunctionalTesting {

    @Autowired
    protected FunctionalTestingConfiguration configuration;
}
@EnableConfigurationProperties(value = {FunctionalTestingConfiguration.class})
public class FunctionalTestingApp  {
}
@EnableAutoConfiguration
@ConfigurationProperties(prefix = "testing")
@Data
public class FunctionalTestingConfiguration {
// the config from yml file
}

我没有testng.xml文件,因为测试是通过spring-boot启动的。 由于某些原因,我想确定测试的优先级,并且发现可以使用QAF(https://qmetry.github.io/qaf/latest/scenario-meta-data.html#pre-defined-meta-data-for-bdd)。 我尝试使用它,但是没有用。

这是我所做的:

我将依赖项添加到pom.xml(我使用黄瓜5)

我将此注释@QAFTestStepProvider添加到了CucumberTestDeFinitions类中

我在RunnerTest类中添加了此插件"com.qmetry.qaf.automation.cucumber.QAFCucumberPlugin"

这是错误

java.lang.NoSuchMethodError: 'java.lang.reflect.Method com.qmetry.qaf.automation.step.client.TestNGScenario.getmethod()'

我尝试在配置文件夹中添加一个testng.xml文件,但没有帮助

QAF弹簧靴兼容吗?

非常感谢您的帮助

编辑

pom.xml:

        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-java</artifactId>
            <version>5.4.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-testng</artifactId>
            <version>5.6.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-spring</artifactId>
            <version>5.4.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.qmetry</groupId>
            <artifactId>qaf-cucumber</artifactId>
            <version>3.0.0</version>
        </dependency>
        
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.5.RELEASE</version>

Runner类

        features = {"src/test/resources/toto"})
public class RunnerTest extends AbstractTestNGCucumberTests {

    @Autowired
    private ObjectMapper objectMapper;

    @Override
    @DataProvider(parallel = true)
    public Object[][] scenarios() {
        return super.scenarios();
    }

    @postconstruct
    public void setUp() {
        objectMapper.registerModule(new JavaTimeModule());
    }

}

错误消息

java.lang.NoSuchMethodError: 'java.lang.reflect.Method com.qmetry.qaf.automation.step.client.TestNGScenario.getmethod()'
    at com.qmetry.qaf.automation.step.client.TestNGScenario.init(TestNGScenario.java:92)
    at com.qmetry.qaf.automation.step.client.TestNGScenario.<init>(TestNGScenario.java:70)
    at com.qmetry.qaf.automation.step.client.TestNGScenario.<init>(TestNGScenario.java:64)
    at com.qmetry.qaf.automation.testng.TestRunnerFactory.convert(TestRunnerFactory.java:76)
    at com.qmetry.qaf.automation.testng.TestRunnerFactory.init(TestRunnerFactory.java:67)
    at com.qmetry.qaf.automation.testng.TestRunnerFactory.newTestRunner(TestRunnerFactory.java:63)
    at org.testng.ITestRunnerFactory.newTestRunner(ITestRunnerFactory.java:55)
    at org.testng.SuiteRunner$ProxyTestRunnerFactory.newTestRunner(SuiteRunner.java:676)
    at org.testng.SuiteRunner.init(SuiteRunner.java:178)
    at org.testng.SuiteRunner.<init>(SuiteRunner.java:112)
    at org.testng.TestNG.createSuiteRunner(TestNG.java:1275)
    at org.testng.TestNG.createSuiteRunners(TestNG.java:1251)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1100)
    at org.testng.TestNG.runSuites(TestNG.java:1039)
    at org.testng.TestNG.run(TestNG.java:1007)
    at com.intellij.rt.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:66)
    at com.intellij.rt.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:110)

解决方法

不幸的是,我无法重现相同的错误并获得有关依赖项的其他错误。但是,要解决您的原始问题“带有弹簧靴的QAF黄瓜testNG”和“喜欢对测试进行优先排序”方面,简短的回答是肯定的。但是TESTNG和Cucumber跑步者可能不会在一起,尤其是对测试进行优先排序。这是什么意思?

当您将黄瓜建议的方式用于TestNG时,它只会在TestNG中创建一个虚拟测试并将场景作为测试数据。哪一个不能将每种情况都视为独立的TestNG测试!因此您将无法从TestNG中获得全部好处(例如,优先级)。

但是,这并不意味着您无法实现或不能同时使用QAF + Cucmber + TestNG。当您使用QAF时,它具有pure TestNG implementation for BDD。 QAF将每个场景视为TestNG测试,并将场景(带有示例场景)作为数据驱动测试。 qaf-cucuber将允许使用黄瓜步骤,包括您选择的依赖注入,在您的情况下为Spring。您将受益于所有TestNG功能,包括并行执行,侦听器和QAF的扩展功能,例如元数据过滤器,测试数据过滤器,

因此,当您要使用TestNG时,最好提供TestNG configuration来运行以BDD2或Gherkin(BDD2的子集)编写的功能文件。您需要做的就是创建以下XML文件,以运行使用BDD2或Gherkin编写的功能文件。

<suite name="QAF Demo" verbose="0">
<parameter name="step.provider.pkg" value="pkg.from.where.steps.needs.tobe.loaded" />
<parameter name="scenario.file.loc" value="src/test/resources/toto" />
<test name="BDD Test" enabled="true">
    <classes>
        <class name="com.qmetry.qaf.automation.step.client.text.BDDTestFactory2"></class>
    </classes>
</test>
</suite>

注意:

    在使用带有步骤中使用的类变量的黄瓜步骤实现时,
  • step.provider.sharedinstance设置为true

  • 以上述方式,由于您没有使用黄瓜浇头,因此不会执行任何黄瓜钩子。使用TestNG时,它可以提供更好的侦听器支持,并且step listener可以与QAF一起使用。因此,如果您实现了任何钩子,则可以在侦听器方法之前/之后将其移动,并在配置文件中注册侦听器。


编辑: 我尝试了您共享的测试项目,与此同时我也遇到了其他问题。终于,我能够弄清楚如下。

POM更新:

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.vaadin.external.google</groupId>
                    <artifactId>android-json</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>6.10</version>
            <scope>test</scope>
        </dependency>

您有两种选择。使用BDD2 Factory为每个场景或黄瓜流氓方式创建TestNGScenario。无论哪种情况,它都应该起作用。您可以在执行后将reporting dashboard添加到view reports

选项1:纯Testng

创建配置文件以使用BDDTestFactory2作为纯Testng测试运行:

<suite name="QAF Demo" verbose="0">
    <parameter name="step.provider.pkg" value="my.custom.packagename.testing"/>
    <parameter name="scenario.file.loc" value="src/test/resources/my/custom/packagename/testing"/>
    <parameter name="step.provider.sharedinstance" value="true" />
    <test name="BDD Test" enabled="true">
        <classes>
            <class name="com.qmetry.qaf.automation.step.client.text.BDDTestFactory2"></class>
        </classes>
    </test>
</suite>

使用此配置文件代替跑步者类。在这种情况下,您不需要黄瓜测试依赖

选项2:Testng的黄瓜赛跑者

  • 您将需要黄瓜-睾丸依赖性
  • 要使用黄瓜赛跑者跑步,请使用相同版本的黄瓜和黄瓜睾丸。在您的情况下,cucumber- *版本必须与5.6.05.4.0相同
  • 更新亚军类,如下所示:
@CucumberOptions(plugin = {"com.qmetry.qaf.automation.cucumber.QAFCucumberPlugin","pretty","html:target","timeline:target"},/*tags = {"@Ignore"},*/
        features = {"src/test/resources/my/custom/packagename/testing"})
public class RunnerTest extends AbstractTestNGCucumberTests {

    @Autowired
    private ObjectMapper objectMapper;
    
    @Test(groups = "cucumber",description = "Runs Cucumber Scenarios",dataProvider = "scenarios")
    public void runScenario(PickleWrapper pickleWrapper,FeatureWrapper featureWrapper) throws Throwable {
        super.runScenario(pickleWrapper,featureWrapper);
    }

    @Override
    @DataProvider(parallel = true,name = "scenarios")
    public Object[][] scenarios() {
        return super.scenarios();
    }

    @PostConstruct
    public void setUp() {
        objectMapper.registerModule(new JavaTimeModule());
    }

}

以TestNG身份运行。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。