我有一个使用spring引导和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启动的。出于某些原因,我想对测试进行优先排序,我发现我可以使用QAF (https://qmetry.github.io/qaf/latest/scenario-meta-data.html#pre-defined-meta-data-for-bdd)。我试过用它,但没用。
在这里我所做的:
我将依赖项添加到pom.xml (我使用黄瓜5)
我将这个注释@QAFTestStepProvider添加到CucumberTestDefinitions类中。
我在"com.qmetry.qaf.automation.cucumber.QAFCucumberPlugin"类中添加了这个插件RunnerTest
在这里,错误
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>跑步者班
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)发布于 2020-09-14 21:19:51
不幸的是,我无法复制相同的错误,也无法获得有关依赖关系的其他错误。然而,要解决您最初的问题"QAF黄瓜testNG与spring引导“和方面”喜欢优先测试“,简短的回答是肯定的。但可能不会同时测试not和Cucumber runner,特别是优先进行测试。这是什么意思?
当您为TestNG使用黄瓜建议的方法时,它只是在TestNG中创建一个虚拟测试,并以提要场景作为测试数据。它将无法将每个场景视为独立的TestNG测试!因此,您将无法从TestNG中获得所有好处(例如,优先级)。
然而,这并不意味着您不能实现或不能一起使用QAF+Cucmber+TestNG。当您使用QAF时,它有BDD的纯TestNG实现。QAF将每个场景视为TestNG测试,并以示例(场景大纲)作为数据驱动测试。qaf-cucuber将允许使用黄瓜步骤,包括您选择的依赖项注入,在您的情况下使用Spring。您将受益于所有的TestNG功能,包括并行执行、监听器和QAF的扩展特性,如元数据过滤器、测试数据过滤器,
因此,当您想要使用TestNG时,最好提供TestNG配置来运行用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。编辑:--我尝试了您共享的测试项目,也遇到了不同的问题。最后,我想出了如下所示。
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工厂,为每个场景或黄瓜运行方式创建TestNGScenario。无论是哪种情况,它都应该有效。您可以在执行后将报告仪表板添加到查看报告。
选项-1:纯测试
使用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:用于测试的黄瓜转轮
5.6.0或5.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的身份运行。
https://stackoverflow.com/questions/63844114
复制相似问题