Running cucumber tests with Junit categories through Maven

I have a maven project with several modules and one common parent module. This unit runs some unit tests with Junit along with surefire, as well as integration tests for BDD Cucumber. I would like to run two separate jobs: one to run all unit tests and one to run BDD / Integration tests. To do this, I annotated my BDD runner classes with a unit category annotation as follows:

@RunWith(Cucumber.class) @CucumberOptions( tags = { "@ATagToBeRun", " ~@ATagNotToBeRun "," ~@ToBeImplemented " }, dryRun = false, strict = true, features = "src/test/resources/cucumber/testing", glue = { "com.some.company.test", "com.some.company.another.test"}) @Category(value = IntegrationTest.class) public class FlowExecutionPojoTest { } 

I created a Maven profile in the parent pom , which uses the maven-surefire-plugin function, which is used to filter the test database on groups. Here is my maven configuration:

  <dependencies> <dependency> <groupId>info.cukes</groupId> <artifactId>cucumber-java</artifactId> <version>1.2.4</version> <scope>test</scope> </dependency> <dependency> <groupId>info.cukes</groupId> <artifactId>cucumber-junit</artifactId> <version>1.2.4</version> <scope>test</scope> </dependency> <dependency> <groupId>info.cukes</groupId> <artifactId>cucumber-spring</artifactId> <version>1.2.4</version> <scope>test</scope> </dependency> <dependency> <groupId>info.cukes</groupId> <artifactId>cucumber-jvm-deps</artifactId> <version>1.0.5</version> <scope>test</scope> </dependency> </dependencies> <profile> <id>testJewels</id> <activation> <activeByDefault>true</activeByDefault> </activation> <modules> <module>../my-module</module> </modules> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.19.1</version> <configuration> <groups>com.some.company.IntegrationTest</groups> </configuration> </plugin> </plugins> </build> </profile> 

I expected that when running mvn test -PtestJewels , classes annotated by the category contained in the <groups> tag should be executed. In fact, none of the annotated classes have been executed.

An interesting point is that when I used the maven-surefire-plugin version 2.18, it worked, but from version 2.18.1 and it didn’t. According to the documentation at the bottom of the page, in version 2.18.1 there have been changes in relation to the inherited categories, but in my case they are in

+6
source share
1 answer

I found that there is actually a pull request problem in the cucumber-jvm repository to fix this specific problem. The problem arises from the fact that when Junit filters the classes of the test runner based on the @Category annotation, it also checks all the child classes. In the case of a cucumber test that runs .feature files, all classes that represent .feature files .feature also checked (the cucumber converts each .feature file to an instance of the FeatureRunner class). Because the annotation does not exist in the FeatureRunner class, tests are filtered out and not run. (Prior to version 2.18.1, the maven-surefire-plugin did not check child annotation classes, and therefore this was not a problem.

The workaround that works for the specific setup described above, where all BDD tests are run in a specific module, is to override the <groups> configuration in the child module, for example:

  <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <configuration> <groups combine.self="override"></groups> </configuration> </plugin> </plugins> </build> 

This, obviously, will not work in another installation, and therefore it is very unfortunate that the team of cucumbers has not yet combined the PR, which I mentioned above.

+2
source

Source: https://habr.com/ru/post/1014345/


All Articles