我有一个使用 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 (我使用 cucumber 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 spring-boot 兼容吗?
非常感谢您的帮助
编辑
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)