Commit 5367d363 authored by Jamie Tanna's avatar Jamie Tanna

Initial commit

- Everything scoped to test
- Tests for the tests
- Failsafe to ensure run as part mvn build
parents
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>me.jvt.hacking</groupId>
<artifactId>fat-cucumber.jar</artifactId>
<version>0.1</version>
<dependencies>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>3.0.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>3.0.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.10.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.22.0</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
package me.jvt.hacking;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
import org.junit.runner.JUnitCore;
import org.junit.runner.RunWith;
@RunWith(Cucumber.class)
@CucumberOptions(plugin = "json:target/report.json", features = {"classpath:features"})
public class RunCukesIT {
}
package me.jvt.hacking;
import cucumber.api.PendingException;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;
import java.util.ArrayList;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
public class Steps {
private List<String> list;
public Steps() {
list = new ArrayList<String>();
}
public Steps(List<String> theList) {
list = theList;
}
@When("I append a new item")
public void appendItemToList() {
list.add("wibble");
}
public List<String> getList() {
return list;
}
@Given("I create a new List")
public void createANewList() {
list = new ArrayList<String>();
}
@Then("^the list has (\\d+) items? in it$")
public void theListHasItemsInIt(int items) {
assertThat(list.size()).isEqualTo(items);
}
}
package me.jvt.hacking;
import org.junit.ComparisonFailure;
import org.junit.Test;
import java.util.ArrayList;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.extractProperty;
public class StepsTest {
private Steps sut = new Steps();
@Test
public void createANewListCreatesANewInstanceOfAnEmptyList () {
List<String> oldList = sut.getList();
sut.createANewList();
List<String> newList = sut.getList();
assertThat(oldList).isNotSameAs(newList);
assertThat(newList).isEmpty();
}
@Test
public void appendNewItemAppendsNewItemToList() {
List<String> list = sut.getList();
sut.appendItemToList();
assertThat(list.size()).isEqualTo(1);
}
@Test
public void appendNewItemThreeTimesAppendsThreeItemsToList() {
List<String> list = sut.getList();
sut.appendItemToList();
sut.appendItemToList();
sut.appendItemToList();
assertThat(list.size()).isEqualTo(3);
}
@Test
public void theListHasItemsInItDoesNotFailWhenExpectedItemsMatchActual() {
List<String> injectedList = new ArrayList<String>();
injectedList.add("Wibble");
injectedList.add("BAR");
injectedList.add("foo");
sut = new Steps(injectedList);
sut.theListHasItemsInIt(3);
// no exception
}
@Test
public void theListHasItemsInItRaisesWhenExpectedItemsDoNotMatchActual() {
List<String> injectedList = new ArrayList<String>();
injectedList.add("Wibble");
injectedList.add("BAR");
injectedList.add("foo");
sut = new Steps(injectedList);
ComparisonFailure actualError = null;
try {
sut.theListHasItemsInIt(5);
} catch(ComparisonFailure e) {
actualError = e;
}
assertThat(actualError.getExpected()).isEqualTo("5");
assertThat(actualError.getActual()).isEqualTo("3");
}
}
Feature: List
Scenario: When I append to a list, it appends
Given I create a new List
When I append a new item
Then the list has 1 item in it
Scenario: When I append to a list, it appends
Given I create a new List
When I append a new item
And I append a new item
Then the list has 2 items in it
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment