Merge cucumber -> testing
This commit is contained in:
@@ -8,4 +8,5 @@
|
||||
- [AssertJ’s Java 8 Features](http://www.baeldung.com/assertJ-java-8-features)
|
||||
- [AssertJ for Guava](http://www.baeldung.com/assertJ-for-guava)
|
||||
- [Introduction to AssertJ](http://www.baeldung.com/introduction-to-assertj)
|
||||
- [Cucumber and Scenario Outline](http://www.baeldung.com/cucumber-scenario-outline)
|
||||
|
||||
|
||||
@@ -18,6 +18,13 @@
|
||||
<version>3.0.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
<artifactId>hamcrest-library</artifactId>
|
||||
<version>${hamcrest.library.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
@@ -31,6 +38,20 @@
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>info.cukes</groupId>
|
||||
<artifactId>cucumber-junit</artifactId>
|
||||
<version>${cucumber.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>info.cukes</groupId>
|
||||
<artifactId>cucumber-java</artifactId>
|
||||
<version>${cucumber.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.pitest</groupId>
|
||||
@@ -111,6 +132,8 @@
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<hamcrest.library.version>1.3</hamcrest.library.version>
|
||||
<cucumber.version>1.2.5</cucumber.version>
|
||||
<pitest.version>1.1.10</pitest.version>
|
||||
<junit.version>4.12</junit.version>
|
||||
<jacoco.version>0.7.7.201606060606</jacoco.version>
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.baeldung.cucumber;
|
||||
|
||||
public class Calculator {
|
||||
public int add(int a, int b) {
|
||||
return a + b;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.baeldung.testing.calculator;
|
||||
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import cucumber.api.CucumberOptions;
|
||||
import cucumber.api.junit.Cucumber;
|
||||
|
||||
@RunWith(Cucumber.class)
|
||||
@CucumberOptions(
|
||||
features={"classpath:features/calculator.feature", "classpath:features/calculator-scenario-outline.feature"}
|
||||
, plugin = { "pretty", "json:target/reports/json/calculator.json" }
|
||||
, glue = {"com.baeldung.cucumber.calculator"}
|
||||
)
|
||||
public class CalculatorIntegrationTest {
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.baeldung.testing.calculator;
|
||||
|
||||
import com.baeldung.cucumber.Calculator;
|
||||
import cucumber.api.java.Before;
|
||||
import cucumber.api.java.en.Given;
|
||||
import cucumber.api.java.en.Then;
|
||||
import cucumber.api.java.en.When;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.Assert;
|
||||
|
||||
public class CalculatorRunSteps {
|
||||
|
||||
private int total;
|
||||
|
||||
private Calculator calculator;
|
||||
|
||||
@Before
|
||||
private void init() {
|
||||
total = -999;
|
||||
|
||||
}
|
||||
|
||||
@Given("^I have a calculator$")
|
||||
public void initializeCalculator() throws Throwable {
|
||||
calculator = new Calculator();
|
||||
}
|
||||
|
||||
@When("^I add (-?\\d+) and (-?\\d+)$")
|
||||
public void testAdd(int num1, int num2) throws Throwable {
|
||||
total = calculator.add(num1, num2);
|
||||
}
|
||||
|
||||
@Then("^the result should be (-?\\d+)$")
|
||||
public void validateResult(int result) throws Throwable {
|
||||
Assert.assertThat(total, Matchers.equalTo(result));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
Feature: Calculator
|
||||
As a user
|
||||
I want to use a calculator to add numbers
|
||||
So that I don't need to add myself
|
||||
|
||||
Scenario Outline: Add two numbers <num1> & <num2>
|
||||
Given I have a calculator
|
||||
When I add <num1> and <num2>
|
||||
Then the result should be <total>
|
||||
|
||||
Examples:
|
||||
| num1 | num2 | total |
|
||||
| -2 | 3 | 1 |
|
||||
| 10 | 15 | 25 |
|
||||
| 99 | -99 | 0 |
|
||||
| -1 | -10 | -11 |
|
||||
@@ -0,0 +1,24 @@
|
||||
Feature: Calculator
|
||||
As a user
|
||||
I want to use a calculator to add numbers
|
||||
So that I don't need to add myself
|
||||
|
||||
Scenario: Add two numbers -2 & 3
|
||||
Given I have a calculator
|
||||
When I add -2 and 3
|
||||
Then the result should be 1
|
||||
|
||||
Scenario: Add two numbers 10 & 15
|
||||
Given I have a calculator
|
||||
When I add 10 and 15
|
||||
Then the result should be 25
|
||||
|
||||
Scenario: Add two numbers 99 & -99
|
||||
Given I have a calculator
|
||||
When I add 99 and -99
|
||||
Then the result should be 0
|
||||
|
||||
Scenario: Add two numbers -1 & -10
|
||||
Given I have a calculator
|
||||
When I add -1 and -10
|
||||
Then the result should be -11
|
||||
Reference in New Issue
Block a user