Java项目在不同模块中运行Cucumber IT

问题描述 投票:0回答:1

我有一个 Java、Spring 项目结构,如下所示:

├── src
│   ├── integrationTest
│   │   ├── java
│   │   │   ├── foo.bar.cuke.project
│   │   │   │   ├── controller
│   │   │   │   │   ├── TestControllerIT.java
│   │   │   │   ├── CucumberSpringConfiguration.java
│   │   │   │   ├── CucumberTest.java
│   │   ├── resources
│   │   │   ├── features
│   │   │   │   ├── test.feature
│   │   │   ├── junit-platform.properties
│   ├── main
│   ├── test

以下是各种文件的样子:

CucumberSpringConfiguration.java

@SpringBootTest(webEnvironment=SpringBootTest.WebEnvironment.RANDOM_PORT)
@CucumberContextConfiguration
public class CucumberSpringConfiguration {
    @Autowired
    protected TestRestTemplate testRestTemplate;
}

CucumberTest.java

@Suite
@SelectClasspathResource("src/integrationTest/resources/features")
public class CucumberTest {
}

TestControllerIT.java

public class TestControllerIT extends CucumberSpringConfiguration {
    @Given("random given text")
    public void testGiven() {
        System.out.println("test");
    }
}

test.feature

Feature: This is a test feature

  Scenario: Test scenario
    Given random given text
    When a condition is met
    Then do something

junit-platform.properties

cucumber.plugin=junit:target/cucumber-reports/cucumber.xml
cucumber.glue=foo.bar.cuke.project.controller

我正在使用 IntelliJ 以及 cucumber 和 gherkin 插件。我不知道要运行什么文件,但是当我运行功能文件时,我收到此错误:

Suppressed: java.lang.SecurityException: class "org.bouncycastle.jcajce.provider.asymmetric.edec.KeyFactorySpi$Ed448"'s signer information does not match signer information of other classes in the same package
        at java.base/java.lang.ClassLoader.checkCerts(ClassLoader.java:1156)
        at java.base/java.lang.ClassLoader.preDefineClass(ClassLoader.java:911)
        at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1020)
        at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:174)
        at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:800)
        at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:698)
        at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:621)
        at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:579)
        at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)

当我运行

CucumberTest
类时,我收到此错误:

> Task :integrationTest
  0 passing (1.9s)
> Task :integrationTest FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':integrationTest'.
> No tests found for given includes: [foo.bar.cuke.project.CucumberTest](--tests filter)

我的设置有什么问题?为什么 Cucumber 无法找到我的 IT 文件并运行测试?

我的技术堆栈是:

  • Java 11
  • Spring框架5.3
  • J单元5
  • 黄瓜7.18
  • 摇篮7.3

我尝试将以下内容添加到我的

build.gradle
但没有成功:

testSets {
    integrationTest
}

test {
    systemProperty 'server.ssl.enabled', false
}

还尝试更改目录结构,将控制器 IT 放在名为

StepDefintions
的目录下。

java spring gradle cucumber integration-testing
1个回答
0
投票

@SelectClasspathResource
应选择类路径上的资源。您的类路径通常不包括
src/integrationTest/resources/

要选择

features
包中的所有功能,您可以使用
@SelectPackage("features")
代替。

© www.soinside.com 2019 - 2024. All rights reserved.