javaspringgradlecucumberintegration-testing

Java Project Run Cucumber IT in different module


I have a Java, spring project structure like so:

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

Here is what the various files look like:

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

I am using IntelliJ with the cucumber and gherkin plugins. I don't know exactly what file to run but when I run the feature file I get this error:

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)

When I run the CucumberTest class, I get this error:

> 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)

What is the issue with my setup? Why is cucumber unable to find my IT file and run the test?

My tech stack is:

I have tried adding the following to my build.gradle to no success:

testSets {
    integrationTest
}

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

Also tried changing the directory structure to have the controller IT under a directory called StepDefintions.


Solution

  • @SelectClasspathResourceshould select a resource on your class path. Your class path does not typically include src/integrationTest/resources/.

    To select all features in the features package you can use @SelectPackage("features") instead.