package com.mycompany.shared.cucumber;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;
import com.mycompany.test.categories.IntegrationTest;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
@Category(IntegrationTest.class)
@RunWith(Cucumber.class)
@CucumberOptions(tags = {"@IntegrationTest" })
public class SampleRunner {
}
My thought was that JUnit would pick up this runner because of the @Category annotation and invoke cucumber with the corresponding "@Integrationtest" cucumber tag. What actually happens is that it just always runs this Cucumber runner no matter what the JUnit category is set to.
Here is what I have in my pom file. In this case, cucumber will not even attempt to run the Cucumber test class that has @IntegrationTest specified. It will however run a plain Junit test with that category.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<groups>com.mycompany.test.categories.IntegrationTest</groups>
</configuration>
</plugin>
<plugins>
<build>
I want three distinct testing steps in the build process: unit, integration and end-to-end. For each of these build steps
I am doing a "mvn test -Pxxx" passing it a profile for unit, integration or end to end. In that profile, as you say, I am
setting up the cucumber tags as you described. For integration testing, by way of example, I expect all cucumber tests
marked @IntegrationTest to run and all plain Junit tests marked @IntegrationTest to also run as a result of that single
maven command. They should generate surefire and cucumber metrics and also total jacoco code coverage metrics for all the
code covered by either kind of test. Because of the fact that Cucumber does not respect JUnit category tags I have to do some
messy things. For instance, remember the effect of this "bug" is this: if I use surefire <groups> to include categories no cucumber
tests will run at all. If I use surefire <excludeGroups> then ALL the surefire tests in the project will run. So the (terrible) hack
is to use <excludeGroups> to exclude every JUnit category I know about except for the one I want and make sure there is only
one cucumber runner class in the project (or filter out any unwanted ones). Thus, I run "mvn test -Pintegration-tests"
with a pom that includes the profile shown below and it kinda works. But it isn't pretty.
<profile>
<id>integration-tests</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1version>
<configuration>
<systemPropertyVariables>
<cucumber.options>src/test/resources/features --tags @IntegrationTest --tags ~@Ignore --strict --monochrome --plugin pretty --plugin html:target/cucumber-results/integration-test-reports --plugin json:target/cucumber-results/integration-test-report.json --plugin junit:target/cucumber-results/integration-test-report.xml</cucumber.options>
</systemPropertyVariables>
<argLine>${jacocoJavaAgent} -Xms512m -Xmx3072m</argLine>
<excludedGroups>test.categories.UnitTest,test.categories.EndToEndTest</excludedGroups>
</configuration>
</plugin>
Thus, I run "mvn test -Pintegration-tests" with a pom that includes the profile shown below and it kinda works. But it isn't pretty. <profile> <id>integration-tests</id> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.18.1version> <configuration> <systemPropertyVariables> <cucumber.options>src/test/resources/features --tags @IntegrationTest --tags ~@Ignore --strict --monochrome --plugin pretty --plugin html:target/cucumber-results/integration-test-reports --plugin json:target/cucumber-results/integration-test-report.json --plugin junit:target/cucumber-results/integration-test-report.xml</cucumber.options> </systemPropertyVariables> <argLine>${jacocoJavaAgent} -Xms512m -Xmx3072m</argLine> <excludedGroups>test.categories.UnitTest,test.categories.EndToEndTest</excludedGroups> </configuration> </plugin>
--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to a topic in the Google Groups "Cukes" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/cukes/jVqbTdwoAPo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to cukes+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.