Commit f4df99fc authored by dbhuller's avatar dbhuller

adding subtract scenario to feature file and subtract method to calculator class

parent ae3635b7
......@@ -2,8 +2,6 @@ package hellocucumber;
public class Calculator {
private int num1;
private int num2;
public Calculator() {
}
......@@ -12,17 +10,12 @@ public class Calculator {
return arg1 + arg2;
}
public int getTotal() {
return total;
public int subtract(int arg1, int arg2) {
return arg1 - arg2;
}
private int total;
public int getNum1() {
return num1;
}
public int getNum2() {
return num2;
}
}
......@@ -3,7 +3,6 @@ package hellocucumber;
import io.cucumber.java.en.Given;
import io.cucumber.java.en.Then;
import io.cucumber.java.en.When;
import org.junit.Assert;
import static org.junit.Assert.assertEquals;
......@@ -31,4 +30,12 @@ public class CalculatorStepDefinitions {
assertEquals(int1, total);
}
//Subtract------------------------------------------
@When("I subtract {int} and {int}")
public void i_subtract_and(int int1, int int2) {
// Write code here that turns the phrase above into concrete actions
total = calculator.subtract(int1, int2);
}
}
......@@ -2,7 +2,7 @@
Feature: Calculator
As a user I want to use a calculator to add two numbers and get a total result
Scenario Outline: Add two number <num1> and <num2>
Scenario Outline: Add two numbers <num1> and <num2>
Given I have a calculator
When I add <num1> and <num2>
Then The result should be <total>
......@@ -12,4 +12,16 @@ Feature: Calculator
| -2 | 3 | 1 |
| 10 | 15 | 25 |
| 99 | -99 | 0 |
| -1 | -10 | -11 |
\ No newline at end of file
| -1 | -10 | -11 |
Scenario Outline: Subtract two numbers <num1> and <num2>
Given I have a calculator
When I subtract <num1> and <num2>
Then The result should be <total>
Examples:
| num1 | num2 | total |
| -2 | 3 | -5 |
| 10 | 15 | -5 |
| 99 | -99 | 198 |
| -1 | -10 | 9 |
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8" ?>
<testsuite tests="4" failures="0" name="hellocucumber.RunCucumberTest" time="0.2" errors="0" skipped="0">
<testsuite tests="8" failures="0" name="hellocucumber.RunCucumberTest" time="0.286" errors="0" skipped="0">
<properties>
<property name="java.runtime.name" value="OpenJDK Runtime Environment"/>
<property name="java.vm.version" value="15.0.2+7"/>
......@@ -57,8 +57,12 @@
<property name="socksNonProxyHosts" value="local|*.local|169.254/16|*.169.254/16"/>
<property name="ftp.nonProxyHosts" value="local|*.local|169.254/16|*.169.254/16"/>
</properties>
<testcase classname="Calculator" name="Add two number -2 and 3" time="0.163"/>
<testcase classname="Calculator" name="Add two number 10 and 15" time="0.012"/>
<testcase classname="Calculator" name="Add two number 99 and -99" time="0.013"/>
<testcase classname="Calculator" name="Add two number -1 and -10" time="0.012"/>
<testcase classname="Calculator" name="Add two numbers -2 and 3" time="0.161"/>
<testcase classname="Calculator" name="Add two numbers 10 and 15" time="0.014"/>
<testcase classname="Calculator" name="Add two numbers 99 and -99" time="0.027"/>
<testcase classname="Calculator" name="Add two numbers -1 and -10" time="0.017"/>
<testcase classname="Calculator" name="Subtract two numbers -2 and 3" time="0.015"/>
<testcase classname="Calculator" name="Subtract two numbers 10 and 15" time="0.017"/>
<testcase classname="Calculator" name="Subtract two numbers 99 and -99" time="0.019"/>
<testcase classname="Calculator" name="Subtract two numbers -1 and -10" time="0.016"/>
</testsuite>
\ No newline at end of file
-------------------------------------------------------------------------------
Test set: hellocucumber.RunCucumberTest
-------------------------------------------------------------------------------
Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.787 sec
Tests run: 8, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.943 sec
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<testsuite errors="0" failures="0" name="io.cucumber.core.plugin.JUnitFormatter" skipped="0" tests="4" time="0.229">
<testcase classname="Calculator" name="Add two number -2 and 3" time="0.058">
<testsuite errors="0" failures="0" name="io.cucumber.core.plugin.JUnitFormatter" skipped="0" tests="8" time="0.321">
<testcase classname="Calculator" name="Add two numbers -2 and 3" time="0.058">
<system-out><![CDATA[Given I have a calculator...................................................passed
When I add -2 and 3.........................................................passed
Then The result should be 1.................................................passed
]]></system-out>
</testcase>
<testcase classname="Calculator" name="Add two number 10 and 15" time="0.003">
<testcase classname="Calculator" name="Add two numbers 10 and 15" time="0.003">
<system-out><![CDATA[Given I have a calculator...................................................passed
When I add 10 and 15........................................................passed
Then The result should be 25................................................passed
]]></system-out>
</testcase>
<testcase classname="Calculator" name="Add two number 99 and -99" time="0.005">
<testcase classname="Calculator" name="Add two numbers 99 and -99" time="0.009">
<system-out><![CDATA[Given I have a calculator...................................................passed
When I add 99 and -99.......................................................passed
Then The result should be 0.................................................passed
]]></system-out>
</testcase>
<testcase classname="Calculator" name="Add two number -1 and -10" time="0.003">
<testcase classname="Calculator" name="Add two numbers -1 and -10" time="0.006">
<system-out><![CDATA[Given I have a calculator...................................................passed
When I add -1 and -10.......................................................passed
Then The result should be -11...............................................passed
]]></system-out>
</testcase>
<testcase classname="Calculator" name="Subtract two numbers -2 and 3" time="0.006">
<system-out><![CDATA[Given I have a calculator...................................................passed
When I subtract -2 and 3....................................................passed
Then The result should be -5................................................passed
]]></system-out>
</testcase>
<testcase classname="Calculator" name="Subtract two numbers 10 and 15" time="0.008">
<system-out><![CDATA[Given I have a calculator...................................................passed
When I subtract 10 and 15...................................................passed
Then The result should be -5................................................passed
]]></system-out>
</testcase>
<testcase classname="Calculator" name="Subtract two numbers 99 and -99" time="0.009">
<system-out><![CDATA[Given I have a calculator...................................................passed
When I subtract 99 and -99..................................................passed
Then The result should be 198...............................................passed
]]></system-out>
</testcase>
<testcase classname="Calculator" name="Subtract two numbers -1 and -10" time="0.004">
<system-out><![CDATA[Given I have a calculator...................................................passed
When I subtract -1 and -10..................................................passed
Then The result should be 9.................................................passed
]]></system-out>
</testcase>
</testsuite>
......@@ -2,7 +2,7 @@
Feature: Calculator
As a user I want to use a calculator to add two numbers and get a total result
Scenario Outline: Add two number <num1> and <num2>
Scenario Outline: Add two numbers <num1> and <num2>
Given I have a calculator
When I add <num1> and <num2>
Then The result should be <total>
......@@ -12,4 +12,16 @@ Feature: Calculator
| -2 | 3 | 1 |
| 10 | 15 | 25 |
| 99 | -99 | 0 |
| -1 | -10 | -11 |
\ No newline at end of file
| -1 | -10 | -11 |
Scenario Outline: Subtract two numbers <num1> and <num2>
Given I have a calculator
When I subtract <num1> and <num2>
Then The result should be <total>
Examples:
| num1 | num2 | total |
| -2 | 3 | -5 |
| 10 | 15 | -5 |
| 99 | -99 | 198 |
| -1 | -10 | 9 |
\ No newline at end of file
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