[BAEL-752] Cucumber with Scenario Outline (#1583)
* [BAEL-752] Cucumbr with Scenario Outline * Corrected indentation * Applied more formatting guidelines. * Java standard used for method names
This commit is contained in:
parent
ad0cd72dfd
commit
fd8e872feb
|
@ -0,0 +1,93 @@
|
||||||
|
<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>com.baeldung</groupId>
|
||||||
|
<artifactId>cucumber</artifactId>
|
||||||
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<java.source.version>1.8</java.source.version>
|
||||||
|
<java.target.version>1.8</java.target.version>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<maven.compiler.plugin.version>3.5.1</maven.compiler.plugin.version>
|
||||||
|
<slf4j.version>1.7.21</slf4j.version>
|
||||||
|
<logback.version>1.1.7</logback.version>
|
||||||
|
<junit.version>4.12</junit.version>
|
||||||
|
<hamcrest.library.version>1.3</hamcrest.library.version>
|
||||||
|
<cucumber.version>1.2.5</cucumber.version>
|
||||||
|
<surefire.plugin.version>2.19.1</surefire.plugin.version>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<modules>
|
||||||
|
</modules>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<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.hamcrest</groupId>
|
||||||
|
<artifactId>hamcrest-library</artifactId>
|
||||||
|
<version>${hamcrest.library.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.slf4j</groupId>
|
||||||
|
<artifactId>slf4j-api</artifactId>
|
||||||
|
<version>${slf4j.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>ch.qos.logback</groupId>
|
||||||
|
<artifactId>logback-classic</artifactId>
|
||||||
|
<version>${logback.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>ch.qos.logback</groupId>
|
||||||
|
<artifactId>logback-core</artifactId>
|
||||||
|
<version>${logback.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>${maven.compiler.plugin.version}</version>
|
||||||
|
<configuration>
|
||||||
|
<verbose>true</verbose>
|
||||||
|
<fork>true</fork>
|
||||||
|
<source>${java.source.version}</source>
|
||||||
|
<target>${java.target.version}</target>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
|
<version>${surefire.plugin.version}</version>
|
||||||
|
<configuration>
|
||||||
|
<includes>
|
||||||
|
<include>**/CalculatorTest.java</include>
|
||||||
|
</includes>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
</project>
|
|
@ -0,0 +1,7 @@
|
||||||
|
package com.baeldung.cucumber.calculator;
|
||||||
|
|
||||||
|
public class Calculator {
|
||||||
|
public int add(int a, int b) {
|
||||||
|
return a + b;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,38 @@
|
||||||
|
package com.baeldung.cucumber.calculator;
|
||||||
|
|
||||||
|
import org.hamcrest.Matchers;
|
||||||
|
import org.junit.Assert;
|
||||||
|
|
||||||
|
import cucumber.api.java.Before;
|
||||||
|
import cucumber.api.java.en.Given;
|
||||||
|
import cucumber.api.java.en.Then;
|
||||||
|
import cucumber.api.java.en.When;
|
||||||
|
|
||||||
|
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,15 @@
|
||||||
|
package com.baeldung.cucumber.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 CalculatorTest {
|
||||||
|
}
|
|
@ -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
|
|
@ -0,0 +1,13 @@
|
||||||
|
<configuration scan="true">
|
||||||
|
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||||
|
<encoder>
|
||||||
|
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n%ex
|
||||||
|
</pattern>
|
||||||
|
</encoder>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
<root level="INFO">
|
||||||
|
<appender-ref ref="STDOUT" />
|
||||||
|
</root>
|
||||||
|
|
||||||
|
</configuration>
|
Loading…
Reference in New Issue