Can cucumber be configured to run the same test with different spring profiles?

I have an application where I am running a trial with various technologies. I have a set of interfaces implemented with each technology and I use spring profiles to decide which technology will work. Each of the technologies has its own spring java config, annotated with the profile for which they are active.

I am running cucumber tests determining which profile is active, but this forces me to manually change the line every time I want to test a different profile, making it impossible to automatically test all of them. Anyway, in a cucumber to provide a set of profiles so that the tests run once for each one?

Thank!

+1


source to share


1 answer


You have two options

  • Standard - Use multiple test classes that are run by Cucumber runners.
  • Write a custom jUnit cucumber (or take a ready-made one) that supports multiple configurations.

In the first case, it will look like this. The downside is that you need to define different reports for each runner and have nearly the same Cucumber runners for each configuration.

enter image description here

This is what the classes look like:

CucumberRunner1.java

@RunWith(Cucumber.class)
@CucumberOptions(glue = {"com.abc.def", "com.abc.common"},
        features = {"classpath:com/abc/def/",
                "classpath:com/abc/common.feature"},
        format = {"json:target/cucumber/cucumber-report-1.json"},
        tags = {"~@ignore"},
        monochrome = true)
public class CucumberRunner1 {
}

      

StepAndConfig1.java



@ContextConfiguration(locations = {"classpath:/com/abc/def/configuration1.xml"})
public class StepsAndConfig1 {
    @Then("^some useful step$")
    public void someStep(){
        int a = 0;
    }
}

      

CucumberRunner2.java

@RunWith(Cucumber.class)
@CucumberOptions(glue = {"com.abc.ghi", "com.abc.common"},
        features = {"classpath:com/abc/ghi/",
                "classpath:com/abc/common.feature"},
        format = {"json:target/cucumber/cucumber-report-2.json"},
        tags = {"~@ignore"},
        monochrome = true)
public class CucumberRunner2 {
}

      

OnlyConfig2.java

@ContextConfiguration(classes = JavaConfig2.class)
public class OnlyConfig2 {
    @Before
    public void justForCucumberToPickupThisClass(){}
}

      

The second approach is to use a custom cucumber that supports multiple configurations. You can either write it yourself, or take a ready-made one, for example mine - CucumberJar.java and the root of the cucumber-junit project . In this case, the Cucumber runner will look like this:

CucumberJarRunner.java

@RunWith(CucumberJar.class)
@CucumberOptions(glue = {"com.abc.common"},
        tags = {"~@ignore"},
        plugin = {"json:target/cucumber/cucumber-report-common.json"})
@CucumberGroupsOptions({
        @CucumberOptions(glue = {"com.abc.def"},
                features = {"classpath:com/abc/def/",
                        "classpath:com/abc/common.feature"}
        ),
        @CucumberOptions(glue = {"com.abc.ghi"},
                features = {"classpath:com/abc/ghi/",
                        "classpath:com/abc/common.feature"}
        )
})
public class CucumberJarRunner {
}

      

+1


source







All Articles