mavenintegration-testingcucumber-jvmcucumber-junit

How do I specify a separate maven goal for running (Cucumber) acceptance tests?


I have the following project structure:

MyProject
   --src
   --test
      --acceptance
         --step_definitions
         --features
      --unit

I would like to be able to run my cucumber tests (in test/acceptance) separately in Maven from the unit tests declared in test/unit, so that they can be run in different CI build plans etc. I am using cucumber-junit so the 'runners' for each acceptance test are written with JUnit.

Is this possible?


Solution

  • Is this possible?

    Yes, it is possible. I believe you should separate your unit from the acceptance/integration tests having:

    Slightly modified folders structure for both of these, placing your integration test files in the standard location of src/it:

    MyProject/

    Moreover, by design, different Maven plugins are intended for unit and integration tests:

    You must also bind execution of maven-failsafe-pulgin. To run the integration tests separately, you can define a new profile:

    <profiles>
      <profile>
        <id>acceptance-tests</id>
        <build>
          <plugins>
            <plugin>
              <artifactId>maven-failsafe-plugin</artifactId>
              <version>2.12</version>
              <executions>
                <execution>
                  <goals>
                    <goal>integration-test</goal>
                    <goal>verify</goal>
                  </goals>
                </execution>
              </executions>
            </plugin>
          </plugins>    
        </build>
      </profile>
    </profiles>
    

    You will also need to configure the plugin to search the src/it directory tree for test cases.

    The acceptance tests can be run afterwards using:

    mvn clean verify -Pacceptance-tests
    

    For complete sample, I'd suggest you to follow http://www.weblogism.com/item/334/integration-tests-with-cucumber-jvm-selenium-and-maven