-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Kingsley Hendrickse
committed
Apr 14, 2012
0 parents
commit d03b5c0
Showing
11 changed files
with
324 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/.project | ||
/.classpath | ||
/.settings | ||
/target | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# An Example [cucumber-jvm](https://github.com/cucumber/cucumber-jvm) Project using Maven | ||
This is an example maven cucumber jvm project that uses maven to build and run some simple scenarios based around withdrawing cash from an ATM. | ||
|
||
## Background | ||
|
||
Cucumber-JVM is a test automation tool following the principles of Behavioural Driven Design and living documentation. Specifications are written in a concise human readable form and executed in continuous integration. | ||
|
||
## Use | ||
|
||
After you have installed maven: mvn clean install will run the tests and produce the test output. There are 3 report formatters - 1 on the console which prints pretty results to the console, there is an html report which gets generated in the target/cucumber directory and finally there is a cucumber.json report which gets published to the target directory. | ||
|
||
Some of the tests pass and some fail to illustrate how they look. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4"> | ||
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_6" inherit-compiler-output="false"> | ||
<output url="file://$MODULE_DIR$/target/classes" /> | ||
<output-test url="file://$MODULE_DIR$/target/test-classes" /> | ||
<content url="file://$MODULE_DIR$"> | ||
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" /> | ||
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" /> | ||
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" isTestSource="true" /> | ||
<sourceFolder url="file://$MODULE_DIR$/target/generated-sources/test-annotations" isTestSource="true" /> | ||
<sourceFolder url="file://$MODULE_DIR$/target/generated-sources/annotations" isTestSource="false" /> | ||
<excludeFolder url="file://$MODULE_DIR$/target/classes" /> | ||
<excludeFolder url="file://$MODULE_DIR$/target/cucumber" /> | ||
<excludeFolder url="file://$MODULE_DIR$/target/surefire" /> | ||
<excludeFolder url="file://$MODULE_DIR$/target/surefire-reports" /> | ||
<excludeFolder url="file://$MODULE_DIR$/target/test-classes" /> | ||
</content> | ||
<orderEntry type="inheritedJdk" /> | ||
<orderEntry type="sourceFolder" forTests="false" /> | ||
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.10" level="project" /> | ||
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.1" level="project" /> | ||
<orderEntry type="library" scope="TEST" name="Maven: info.cukes:cucumber-junit:1.0.2" level="project" /> | ||
<orderEntry type="library" scope="TEST" name="Maven: info.cukes:cucumber-core:1.0.2" level="project" /> | ||
<orderEntry type="library" scope="TEST" name="Maven: info.cukes:gherkin:2.9.3" level="project" /> | ||
<orderEntry type="library" scope="TEST" name="Maven: info.cukes:cucumber-html:0.2.1" level="project" /> | ||
<orderEntry type="library" scope="TEST" name="Maven: info.cukes:cucumber-java:1.0.2" level="project" /> | ||
<orderEntry type="library" scope="TEST" name="Maven: info.cukes:cucumber-picocontainer:1.0.2" level="project" /> | ||
<orderEntry type="library" scope="TEST" name="Maven: org.picocontainer:picocontainer:2.10.2" level="project" /> | ||
<orderEntry type="library" scope="TEST" name="Maven: javax.annotation:jsr250-api:1.0" level="project" /> | ||
<orderEntry type="library" scope="TEST" name="Maven: javax.inject:javax.inject:1" level="project" /> | ||
</component> | ||
</module> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<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>net.masterthought.example</groupId> | ||
<artifactId>cucumber-jvm-example</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<configuration> | ||
<source>1.6</source> | ||
<target>1.6</target> | ||
</configuration> | ||
</plugin> | ||
|
||
|
||
</plugins> | ||
</build> | ||
|
||
<dependencies> | ||
<!-- JUnit --> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>4.10</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<!-- Cucumber --> | ||
<dependency> | ||
<groupId>info.cukes</groupId> | ||
<artifactId>cucumber-junit</artifactId> | ||
<version>1.0.2</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>info.cukes</groupId> | ||
<artifactId>cucumber-html</artifactId> | ||
<version>0.2.1</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>info.cukes</groupId> | ||
<artifactId>cucumber-java</artifactId> | ||
<version>1.0.2</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>info.cukes</groupId> | ||
<artifactId>cucumber-picocontainer</artifactId> | ||
<version>1.0.2</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.picocontainer</groupId> | ||
<artifactId>picocontainer</artifactId> | ||
<version>2.10.2</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<repositories> | ||
<repository> | ||
<id>sonatype-snapshots</id> | ||
<url>https://oss.sonatype.org/content/repositories/snapshots</url> | ||
</repository> | ||
</repositories> | ||
|
||
|
||
|
||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package net.masterthought.example; | ||
|
||
public class ATM { | ||
|
||
private int money; | ||
|
||
public ATM(int money) { | ||
this.money = money; | ||
} | ||
|
||
public int requestMoney(CreditCard creditCard, int amount) { | ||
if (!creditCard.isValid() || amount > money) { | ||
return 0; | ||
} | ||
|
||
amount = creditCard.getAccount().getMoney(amount); | ||
|
||
money = money - amount; | ||
|
||
return amount; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package net.masterthought.example; | ||
|
||
public class Account { | ||
|
||
private int balance; | ||
|
||
public Account(int balance) { | ||
this.balance = balance; | ||
} | ||
|
||
public int getBalance() { | ||
return balance; | ||
} | ||
|
||
public int getMoney(int amount) { | ||
if (balance < amount) | ||
return 0; | ||
|
||
balance = balance - amount; | ||
|
||
return amount; | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package net.masterthought.example; | ||
|
||
public class CreditCard { | ||
|
||
private boolean valid = true; | ||
private boolean inUse = false; | ||
|
||
private final Account account; | ||
|
||
public CreditCard(Account account) { | ||
this.account = account; | ||
} | ||
|
||
public boolean isValid() { | ||
return valid; | ||
} | ||
|
||
public Account getAccount() { | ||
return account; | ||
} | ||
|
||
public void insertCard(){ | ||
inUse = true; | ||
} | ||
|
||
public void returnCard(){ | ||
inUse = false; | ||
} | ||
|
||
public boolean isInUse() { | ||
return inUse; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package net.masterthought.example; | ||
|
||
import static org.hamcrest.core.Is.is; | ||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertThat; | ||
import cucumber.annotation.en.And; | ||
import cucumber.annotation.en.Given; | ||
import cucumber.annotation.en.Then; | ||
import cucumber.annotation.en.When; | ||
import net.masterthought.example.ATM; | ||
import net.masterthought.example.Account; | ||
import net.masterthought.example.CreditCard; | ||
|
||
public class ATMScenario { | ||
|
||
private ATM atm; | ||
private Account account; | ||
private CreditCard creditCard; | ||
|
||
private int money; | ||
|
||
@Given("^the account balance is (\\d*)$") | ||
public void createAccount(int balance) { | ||
account = new Account(balance); | ||
} | ||
|
||
@And("^the card is valid$") | ||
public void createCreditCard() { | ||
creditCard = new CreditCard(account); | ||
} | ||
|
||
@And("^the machine contains (\\d*)$") | ||
public void createATM(int money) { | ||
atm = new ATM(money); | ||
} | ||
|
||
@When("^the Account Holder requests (\\d*)$") | ||
public void requestMoney(int amount) { | ||
money = atm.requestMoney(creditCard, amount); | ||
} | ||
|
||
@Then("^the ATM should dispense (\\d*)$") | ||
public void checkMoney(int amount) { | ||
assertThat(money, is(amount)); | ||
} | ||
|
||
@And("^the account balance should be (\\d*)$") | ||
public void checkBalance(int newBalance) { | ||
assertThat(newBalance, is(creditCard.getAccount().getBalance())); | ||
} | ||
|
||
@And("^the card should be returned$") | ||
public void cardShouldBeReturned() { | ||
assertFalse(creditCard.isInUse()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package net.masterthought.example; | ||
|
||
import cucumber.junit.Cucumber; | ||
import org.junit.runner.RunWith; | ||
|
||
@RunWith(Cucumber.class) | ||
@Cucumber.Options(format = {"pretty", "html:target/cucumber", "json:target/cucumber.json"}) | ||
public class ATMTest { | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
Feature: Account Holder withdraws cash | ||
As an Account Holder | ||
I want to withdraw cash from an ATM | ||
So that I can get money when the bank is closed | ||
|
||
@myone | ||
Scenario Outline: Account has sufficient funds | ||
Given the account balance is <account_balance> | ||
And the card is valid | ||
And the machine contains <atm_available> | ||
When the Account Holder requests <request> | ||
Then the ATM should dispense <result> | ||
And the account balance should be <newBalance> | ||
And the card should be returned | ||
|
||
Examples: | ||
|account_balance|atm_available|request|result|newBalance| | ||
|1004 |100 |20 |20 |80 | | ||
|1001 |100 |20 |20 |80 | | ||
|
||
Scenario: Account has sufficient funds again | ||
Given the account balance is 300 | ||
And the card is valid | ||
And the machine contains 300 | ||
When the Account Holder requests 20 | ||
Then the ATM should dispense 20 | ||
And the account balance should be 280 | ||
And the card should be returned | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
Feature: Account Holder withdraws cash | ||
As an Account Holder | ||
I want to withdraw cash from an ATM | ||
So that I can get money when the bank is closed | ||
|
||
Scenario Outline: Account has sufficient funds | ||
Given the account balance is <account_balance> | ||
And the card is valid | ||
And the machine contains <atm_available> | ||
When the Account Holder requests <request> | ||
Then the ATM should dispense <result> | ||
And the account balance should be <newBalance> | ||
And the card should be returned | ||
|
||
Examples: | ||
|account_balance|atm_available|request|result|newBalance| | ||
|100 |100 |20 |20 |80 | | ||
|