0

Initially I had:

@RunWith(Cucumber.class)
@CucumberOptions(
        features = "src/acceptance-test/resources"
)
public class TestAcceptance {
}

But, my features was crossing between environment (test of Quality was performed in Develop).

My structure directories is:

enter image description here I was trying with test.gradle file:

sourceSets {
    acceptanceTest {
        java {
            compileClasspath += sourceSets.main.output
            runtimeClasspath += sourceSets.main.output
            srcDirs = ['src/acceptance-test/java']
        }
        resources.srcDir file('src/acceptance-test/resources')
    }
}
task acceptanceTest(type: Test) {
    testClassesDirs = sourceSets.acceptanceTest.output.classesDirs
    classpath = sourceSets.acceptanceTest.runtimeClasspath
    options {
        final String ambiente = "src/acceptance-test/resources/" + System.getenv("MY_ENVIRONMENT_VARIABLE")
        jvmArgs = ['-Dcucumber.options= --plugin pretty --tags ~@ignore --glue acceptance.steps ' + ambiente]
    }
}

test {
    useJUnitPlatform()
    jvmArgs "-Xms2g", "-Xmx2g", "-XX:+DisableExplicitGC"
    finalizedBy jacocoTestReport
}

I was working with some class with this content:

@Configuration
@ComponentScan("acceptance")
@PropertySource(value = "classpath:/${MY_ENVIRONMENT_VARIABLE}/acceptance-test.properties")
public class TestConfig {

    @Bean
    public WebClient webClient() {
        return WebClient
                .builder()
                .build();
    }
}

Now I would like to use to set the features according to environment as:

@RunWith(Cucumber.class)
@CucumberOptions(
        features = "src/acceptance-test/resources${MY_ENVIRONMENT_VARIABLE}"
)
public class TestAcceptance {
}

But I get:

> Task :app:acceptanceTest FAILED

path must exist: /Users/___HIDDEN___/app/src/acceptance-test/resources/${MY_ENVIRONMENT_VARIABLE}
java.lang.IllegalArgumentException: path must exist: /Users/___HIDDEN___/app/src/acceptance-test/resources/${MY_ENVIRONMENT_VARIABLE}
        at io.cucumber.core.resource.PathScanner.findResourcesForPath(PathScanner.java:44)
        at io.cucumber.core.resource.PathScanner.findResourcesForUri(PathScanner.java:28)
        at io.cucumber.core.resource.ResourceScanner.findResourcesForUri(ResourceScanner.java:61)
        at io.cucumber.core.resource.ResourceScanner.scanForResourcesUri(ResourceScanner.java:134)
        at io.cucumber.core.runtime.FeaturePathFeatureSupplier.loadFeatures(FeaturePathFeatureSupplier.java:62)
        at io.cucumber.core.runtime.FeaturePathFeatureSupplier.get(FeaturePathFeatureSupplier.java:45)
        at io.cucumber.junit.Cucumber.<init>(Cucumber.java:158)
        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
        at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:104)
        at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:86)
        at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:70)
        at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:37)
        at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:70)
        at org.junit.internal.requests.ClassRequest.createRunner(ClassRequest.java:28)
        at org.junit.internal.requests.MemoizingRequest.getRunner(MemoizingRequest.java:19)
        at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.runTestClass(JUnitTestClassExecutor.java:78)
        at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute(JUnitTestClassExecutor.java:58)
        at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute(JUnitTestClassExecutor.java:38)
        at org.gradle.api.internal.tasks.testing.junit.AbstractJUnitTestClassProcessor.processTestClass(AbstractJUnitTestClassProcessor.java:62)
        at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:51)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

enter image description here

Then I found this answer https://stackoverflow.com/a/45095733/811293 and I changed my code:

enter image description here

Execution failed for task ':app:acceptanceTest'.
> No tests found for given includes: [acceptance.TestAcceptance](--tests filter)

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

Definitely is not posible to addapt features argument value to environment variable? If yes... how I can do it?

joseluisbz
  • 1,491
  • 1
  • 36
  • 58
  • You're using `cucumber.options`, what makes you believe this property works? – M.P. Korstanje Jan 22 '23 at 11:55
  • It is precisely part of my question. Obviously I know that I wrong! But I don't know where is my mistake or what part is wrong and how to fix it.... if is this possible. Could you think I'm completely lost? – joseluisbz Jan 22 '23 at 22:03
  • That's why I asked. You have a property name, you have heard/read about it somehow. Did you read about it in the documentation? – M.P. Korstanje Jan 22 '23 at 23:12

0 Answers0