Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 545
Rich Ashworth Avatar asked Aug 10 '13 17:08

Rich Ashworth


People also ask

How to run cucumber test in Java using Maven?

In that case we can create a Class that defines the runner configurations which then able to run cucumber test in java. Here’s how: First, create a Class that ends with Test in name. For example, CucumberTest.java. I noticed that if your class name doesn’t end with Test, maven doesn’t call that Class.

How to run cucumber tests from command-line?

The 2 most commonly used ways to execute tests in Cucumber Framework are by running the tests using JUnit and Maven. To execute tests using JUnit, we need to create a JUnit Test Runner. Whereas, we need a Maven project to execute Cucumber tests from Command-Line. Create a Maven project and add the below-mentioned dependencies to your Maven project.

How do I run cucumber features in MVN?

All feature files should be in src/test/resources and create the Cucumber Runner class as CucumberRunnerTest. mvn test runs Cucumber Features using Cucumber’s JUnit Runner. The @RunWith (Cucumber.class) annotation on the TestRunner class tells JUnit to start Cucumber.

How do I run a cucumber class In JUnit?

Here’s how: First, create a Class that ends with Test in name. For example, CucumberTest.java. I noticed that if your class name doesn’t end with Test, maven doesn’t call that Class. Next, add a @RunWith annotation in your class and put Cucumber.class inside. It defines how JUnit can run your class.


1 Answers

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/

  • src/main/java/ (SUT)
  • src/test/ (unit test code)
    • java/
    • resources/
  • src/it/ (acceptance/integration tests)
    • java/ (steps definitions)
    • resources/ (feature files)

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

  • for unit tests: maven-surefire-plugin
  • for acceptance/integration tests: maven-failsafe-plugin

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

like image 108
Peter Butkovic Avatar answered Sep 19 '22 05:09

Peter Butkovic