0

I am trying to use Localstack to emulate AWS in my integration tests. The authors instruct us to integrate Localstack with our Java tests as follows:

import cloud.localstack.LocalstackTestRunner;
import cloud.localstack.TestUtils;

@RunWith(LocalstackTestRunner.class)
public class MyCloudAppTest {

However, my cucumber test is as follows:

@RunWith(Cucumber.class)
@CucumberOptions(  monochrome = true,
        features = "src/test/resources/",
        glue = "com/mydomain/services" )
public class MyFeatureTest {
}

Since I cannot have two RunWith annotations, can anyone suggest an alternative to have both Localstack and cucumber for testing?

Thank you for your help.

João Matos
  • 6,102
  • 5
  • 41
  • 76
  • You can call cucumber using the Main class of cucumber.api.cli package in a junit test method. No runner is required. You can just use the localstack runwith annotation. https://stackoverflow.com/questions/46807307/how-to-run-cucumber-feature-file-from-java-code-not-from-junit-runner/46824994#46824994 – Grasshopper Apr 27 '19 at 05:25

1 Answers1

0

I took the advice of @Grasshopper and got it working as follows:

@RunWith(LocalstackDockerTestRunner.class)
@LocalstackDockerProperties(services = {"dynamodb"})
public class MyFeatureTest {

    @Test
    public void test() throws IOException {
        String [] argv = new String[]{ "-g","com/mydomain/services","./src/test/resources/myFeature.feature"};
        ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
        cucumber.api.cli.Main.run(argv, contextClassLoader);
    }

}
João Matos
  • 6,102
  • 5
  • 41
  • 76