I'm not too sure if this is an issue, but I thought I'd post my findings and see if anyone else is experiencing the same behavior. Recently, I began experimenting running my tests using the
argument and without JUnit. I notice that when I run the test using JUnit, the last step, which is designed to intentionally fail, does what is expected of it (ie, fails), and Maven reports a build failure. However, when I opt to not use JUnit and instead use the
. I would have thought that the build should fail as it did when run with JUnit -- I think I might be overlooking something here :(. I've included my step def file below, along with a copy of my pom file, and the output from each run.
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running org.stag.hello.HelloTest
Before step
Tests run: 3, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.538 sec <<< FAILURE!
Results :
Failed tests:
Then the expected behavior is displayed: This step is designed to intentionally FAIL
Tests run: 3, Failures: 1, Errors: 0, Skipped: 0
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
Test Run Results without JUnit
[INFO] --- exec-maven-plugin:1.2.1:java (default) @ simple-cucumber-jvm ---
Feature: My hello feature
Before step
Background: My background # /hello.feature:2
Given a background # HelloStepDefs.background()
Scenario: Saying hello # /hello.feature:5
Given a precondition # HelloStepDefs.givenStep()
When an action takes place # HelloStepDefs.whenStep()
Then the expected behavior is displayed # HelloStepDefs.thenStep()
junit.framework.AssertionFailedError: This step is designed to intentionally FAIL
at junit.framework.Assert.fail(Assert.java:47)
at junit.framework.Assert.assertTrue(Assert.java:20)
at org.stag.hello.HelloStepDefs.thenStep(HelloStepDefs.java:33)
at ✽.Then the expected behavior is displayed(/hello.feature:8)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
Step Def File
package org.stag.hello;
import cucumber.annotation.Before;
import cucumber.annotation.en.Given;
import cucumber.annotation.en.Then;
import cucumber.annotation.en.When;
import static junit.framework.Assert.*;
public class HelloStepDefs {
@Before
public void beforeStep() {
System.out.println("Before step");
}
@Given("^a background$")
public void background() {
assertTrue(true);
}
@Given("^a precondition$")
public void givenStep() {
assertTrue(true);
}
@When("^an action takes place$")
public void whenStep() {
assertTrue(true);
}
@Then("^the expected behavior is displayed$")
public void thenStep() {
assertTrue("This step is designed to intentionally FAIL", false);
}
}
POM File (setup to run test without JUnit)
<modelVersion>4.0.0</modelVersion>
<groupId>org.stag.simplecucumber</groupId>
<artifactId>simple-cucumber-jvm</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<cucumber-jvm.version>1.0.0-SNAPSHOT</cucumber-jvm.version>
<junit.version>4.8.2</junit.version>
<picocontainer.version>2.13.6</picocontainer.version>
</properties>
<dependencies>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-picocontainer</artifactId>
<version>${cucumber-jvm.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<version>${cucumber-jvm.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
</dependency>
<dependency>
<groupId>org.picocontainer</groupId>
<artifactId>picocontainer</artifactId>
<version>${picocontainer.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.10</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>java</goal>
</goals>
<configuration>
<classpathScope>test</classpathScope>
<mainClass>cucumber.cli.Main</mainClass>
<arguments>
<argument>--format</argument>
<argument>pretty</argument>
<argument>--glue</argument>
<argument>org.stag.hello</argument>
<argument>.</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>