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; ...@@ -2,8 +2,6 @@ package hellocucumber;
public class Calculator { public class Calculator {
private int num1;
private int num2;
public Calculator() { public Calculator() {
} }
...@@ -12,17 +10,12 @@ public class Calculator { ...@@ -12,17 +10,12 @@ public class Calculator {
return arg1 + arg2; return arg1 + arg2;
} }
public int getTotal() { public int subtract(int arg1, int arg2) {
return total; return arg1 - arg2;
} }
private int total;
public int getNum1() {
return num1;
}
public int getNum2() {
return num2;
}
} }
...@@ -3,7 +3,6 @@ package hellocucumber; ...@@ -3,7 +3,6 @@ package hellocucumber;
import io.cucumber.java.en.Given; import io.cucumber.java.en.Given;
import io.cucumber.java.en.Then; import io.cucumber.java.en.Then;
import io.cucumber.java.en.When; import io.cucumber.java.en.When;
import org.junit.Assert;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
...@@ -31,4 +30,12 @@ public class CalculatorStepDefinitions { ...@@ -31,4 +30,12 @@ public class CalculatorStepDefinitions {
assertEquals(int1, total); 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 @@ ...@@ -2,7 +2,7 @@
Feature: Calculator Feature: Calculator
As a user I want to use a calculator to add two numbers and get a total result 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 Given I have a calculator
When I add <num1> and <num2> When I add <num1> and <num2>
Then The result should be <total> Then The result should be <total>
...@@ -12,4 +12,16 @@ Feature: Calculator ...@@ -12,4 +12,16 @@ Feature: Calculator
| -2 | 3 | 1 | | -2 | 3 | 1 |
| 10 | 15 | 25 | | 10 | 15 | 25 |
| 99 | -99 | 0 | | 99 | -99 | 0 |
| -1 | -10 | -11 | | -1 | -10 | -11 |
\ No newline at end of file
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" ?> <?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> <properties>
<property name="java.runtime.name" value="OpenJDK Runtime Environment"/> <property name="java.runtime.name" value="OpenJDK Runtime Environment"/>
<property name="java.vm.version" value="15.0.2+7"/> <property name="java.vm.version" value="15.0.2+7"/>
...@@ -57,8 +57,12 @@ ...@@ -57,8 +57,12 @@
<property name="socksNonProxyHosts" value="local|*.local|169.254/16|*.169.254/16"/> <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"/> <property name="ftp.nonProxyHosts" value="local|*.local|169.254/16|*.169.254/16"/>
</properties> </properties>
<testcase classname="Calculator" name="Add two number -2 and 3" time="0.163"/> <testcase classname="Calculator" name="Add two numbers -2 and 3" time="0.161"/>
<testcase classname="Calculator" name="Add two number 10 and 15" time="0.012"/> <testcase classname="Calculator" name="Add two numbers 10 and 15" time="0.014"/>
<testcase classname="Calculator" name="Add two number 99 and -99" time="0.013"/> <testcase classname="Calculator" name="Add two numbers 99 and -99" time="0.027"/>
<testcase classname="Calculator" name="Add two number -1 and -10" time="0.012"/> <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> </testsuite>
\ No newline at end of file
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Test set: hellocucumber.RunCucumberTest 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
...@@ -3,17 +3,17 @@ ...@@ -3,17 +3,17 @@
"line": 2, "line": 2,
"elements": [ "elements": [
{ {
"start_timestamp": "2021-04-06T20:11:34.964Z", "start_timestamp": "2021-04-06T20:20:59.332Z",
"line": 12, "line": 12,
"name": "Add two number -2 and 3", "name": "Add two numbers -2 and 3",
"description": "", "description": "",
"id": "calculator;add-two-number-\u003cnum1\u003e-and-\u003cnum2\u003e;;2", "id": "calculator;add-two-numbers-\u003cnum1\u003e-and-\u003cnum2\u003e;;2",
"type": "scenario", "type": "scenario",
"keyword": "Scenario Outline", "keyword": "Scenario Outline",
"steps": [ "steps": [
{ {
"result": { "result": {
"duration": 2166000, "duration": 2179000,
"status": "passed" "status": "passed"
}, },
"line": 6, "line": 6,
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
}, },
{ {
"result": { "result": {
"duration": 633000, "duration": 545000,
"status": "passed" "status": "passed"
}, },
"line": 7, "line": 7,
...@@ -47,7 +47,7 @@ ...@@ -47,7 +47,7 @@
}, },
{ {
"result": { "result": {
"duration": 1176000, "duration": 1097000,
"status": "passed" "status": "passed"
}, },
"line": 8, "line": 8,
...@@ -71,17 +71,17 @@ ...@@ -71,17 +71,17 @@
] ]
}, },
{ {
"start_timestamp": "2021-04-06T20:11:35.037Z", "start_timestamp": "2021-04-06T20:20:59.404Z",
"line": 13, "line": 13,
"name": "Add two number 10 and 15", "name": "Add two numbers 10 and 15",
"description": "", "description": "",
"id": "calculator;add-two-number-\u003cnum1\u003e-and-\u003cnum2\u003e;;3", "id": "calculator;add-two-numbers-\u003cnum1\u003e-and-\u003cnum2\u003e;;3",
"type": "scenario", "type": "scenario",
"keyword": "Scenario Outline", "keyword": "Scenario Outline",
"steps": [ "steps": [
{ {
"result": { "result": {
"duration": 205000, "duration": 345000,
"status": "passed" "status": "passed"
}, },
"line": 6, "line": 6,
...@@ -93,7 +93,7 @@ ...@@ -93,7 +93,7 @@
}, },
{ {
"result": { "result": {
"duration": 308000, "duration": 325000,
"status": "passed" "status": "passed"
}, },
"line": 7, "line": 7,
...@@ -115,7 +115,7 @@ ...@@ -115,7 +115,7 @@
}, },
{ {
"result": { "result": {
"duration": 265000, "duration": 246000,
"status": "passed" "status": "passed"
}, },
"line": 8, "line": 8,
...@@ -139,17 +139,17 @@ ...@@ -139,17 +139,17 @@
] ]
}, },
{ {
"start_timestamp": "2021-04-06T20:11:35.047Z", "start_timestamp": "2021-04-06T20:20:59.424Z",
"line": 14, "line": 14,
"name": "Add two number 99 and -99", "name": "Add two numbers 99 and -99",
"description": "", "description": "",
"id": "calculator;add-two-number-\u003cnum1\u003e-and-\u003cnum2\u003e;;4", "id": "calculator;add-two-numbers-\u003cnum1\u003e-and-\u003cnum2\u003e;;4",
"type": "scenario", "type": "scenario",
"keyword": "Scenario Outline", "keyword": "Scenario Outline",
"steps": [ "steps": [
{ {
"result": { "result": {
"duration": 227000, "duration": 192000,
"status": "passed" "status": "passed"
}, },
"line": 6, "line": 6,
...@@ -161,7 +161,7 @@ ...@@ -161,7 +161,7 @@
}, },
{ {
"result": { "result": {
"duration": 738000, "duration": 1015000,
"status": "passed" "status": "passed"
}, },
"line": 7, "line": 7,
...@@ -183,7 +183,7 @@ ...@@ -183,7 +183,7 @@
}, },
{ {
"result": { "result": {
"duration": 336000, "duration": 296000,
"status": "passed" "status": "passed"
}, },
"line": 8, "line": 8,
...@@ -207,17 +207,17 @@ ...@@ -207,17 +207,17 @@
] ]
}, },
{ {
"start_timestamp": "2021-04-06T20:11:35.061Z", "start_timestamp": "2021-04-06T20:20:59.445Z",
"line": 15, "line": 15,
"name": "Add two number -1 and -10", "name": "Add two numbers -1 and -10",
"description": "", "description": "",
"id": "calculator;add-two-number-\u003cnum1\u003e-and-\u003cnum2\u003e;;5", "id": "calculator;add-two-numbers-\u003cnum1\u003e-and-\u003cnum2\u003e;;5",
"type": "scenario", "type": "scenario",
"keyword": "Scenario Outline", "keyword": "Scenario Outline",
"steps": [ "steps": [
{ {
"result": { "result": {
"duration": 279000, "duration": 387000,
"status": "passed" "status": "passed"
}, },
"line": 6, "line": 6,
...@@ -229,7 +229,7 @@ ...@@ -229,7 +229,7 @@
}, },
{ {
"result": { "result": {
"duration": 307000, "duration": 814000,
"status": "passed" "status": "passed"
}, },
"line": 7, "line": 7,
...@@ -251,7 +251,7 @@ ...@@ -251,7 +251,7 @@
}, },
{ {
"result": { "result": {
"duration": 311000, "duration": 442000,
"status": "passed" "status": "passed"
}, },
"line": 8, "line": 8,
...@@ -273,6 +273,278 @@ ...@@ -273,6 +273,278 @@
"name": "@wip" "name": "@wip"
} }
] ]
},
{
"start_timestamp": "2021-04-06T20:20:59.462Z",
"line": 24,
"name": "Subtract two numbers -2 and 3",
"description": "",
"id": "calculator;subtract-two-numbers-\u003cnum1\u003e-and-\u003cnum2\u003e;;2",
"type": "scenario",
"keyword": "Scenario Outline",
"steps": [
{
"result": {
"duration": 898000,
"status": "passed"
},
"line": 18,
"name": "I have a calculator",
"match": {
"location": "hellocucumber.CalculatorStepDefinitions.i_have_a_calculator()"
},
"keyword": "Given "
},
{
"result": {
"duration": 728000,
"status": "passed"
},
"line": 19,
"name": "I subtract -2 and 3",
"match": {
"arguments": [
{
"val": "-2",
"offset": 11
},
{
"val": "3",
"offset": 18
}
],
"location": "hellocucumber.CalculatorStepDefinitions.i_subtract_and(int,int)"
},
"keyword": "When "
},
{
"result": {
"duration": 375000,
"status": "passed"
},
"line": 20,
"name": "The result should be -5",
"match": {
"arguments": [
{
"val": "-5",
"offset": 21
}
],
"location": "hellocucumber.CalculatorStepDefinitions.the_result_should_be(int)"
},
"keyword": "Then "
}
],
"tags": [
{
"name": "@wip"
}
]
},
{
"start_timestamp": "2021-04-06T20:20:59.476Z",
"line": 25,
"name": "Subtract two numbers 10 and 15",
"description": "",
"id": "calculator;subtract-two-numbers-\u003cnum1\u003e-and-\u003cnum2\u003e;;3",
"type": "scenario",
"keyword": "Scenario Outline",
"steps": [
{
"result": {
"duration": 1136000,
"status": "passed"
},
"line": 18,
"name": "I have a calculator",
"match": {
"location": "hellocucumber.CalculatorStepDefinitions.i_have_a_calculator()"
},
"keyword": "Given "
},
{
"result": {
"duration": 543000,
"status": "passed"
},
"line": 19,
"name": "I subtract 10 and 15",
"match": {
"arguments": [
{
"val": "10",
"offset": 11
},
{
"val": "15",
"offset": 18
}
],
"location": "hellocucumber.CalculatorStepDefinitions.i_subtract_and(int,int)"
},
"keyword": "When "
},
{
"result": {
"duration": 261000,
"status": "passed"
},
"line": 20,
"name": "The result should be -5",
"match": {
"arguments": [
{
"val": "-5",
"offset": 21
}
],
"location": "hellocucumber.CalculatorStepDefinitions.the_result_should_be(int)"
},
"keyword": "Then "
}
],
"tags": [
{
"name": "@wip"
}
]
},
{
"start_timestamp": "2021-04-06T20:20:59.493Z",
"line": 26,
"name": "Subtract two numbers 99 and -99",
"description": "",
"id": "calculator;subtract-two-numbers-\u003cnum1\u003e-and-\u003cnum2\u003e;;4",
"type": "scenario",
"keyword": "Scenario Outline",
"steps": [
{
"result": {
"duration": 567000,
"status": "passed"
},
"line": 18,
"name": "I have a calculator",
"match": {
"location": "hellocucumber.CalculatorStepDefinitions.i_have_a_calculator()"
},
"keyword": "Given "
},
{
"result": {
"duration": 283000,
"status": "passed"
},
"line": 19,
"name": "I subtract 99 and -99",
"match": {
"arguments": [
{
"val": "99",
"offset": 11
},
{
"val": "-99",
"offset": 18
}
],
"location": "hellocucumber.CalculatorStepDefinitions.i_subtract_and(int,int)"
},
"keyword": "When "
},
{
"result": {
"duration": 522000,
"status": "passed"
},
"line": 20,
"name": "The result should be 198",
"match": {
"arguments": [
{
"val": "198",
"offset": 21
}
],
"location": "hellocucumber.CalculatorStepDefinitions.the_result_should_be(int)"
},
"keyword": "Then "
}
],
"tags": [
{
"name": "@wip"
}
]
},
{
"start_timestamp": "2021-04-06T20:20:59.516Z",
"line": 27,
"name": "Subtract two numbers -1 and -10",
"description": "",
"id": "calculator;subtract-two-numbers-\u003cnum1\u003e-and-\u003cnum2\u003e;;5",
"type": "scenario",
"keyword": "Scenario Outline",
"steps": [
{
"result": {
"duration": 146000,
"status": "passed"
},
"line": 18,
"name": "I have a calculator",
"match": {
"location": "hellocucumber.CalculatorStepDefinitions.i_have_a_calculator()"
},
"keyword": "Given "
},
{
"result": {
"duration": 361000,
"status": "passed"
},
"line": 19,
"name": "I subtract -1 and -10",
"match": {
"arguments": [
{
"val": "-1",
"offset": 11
},
{
"val": "-10",
"offset": 18
}
],
"location": "hellocucumber.CalculatorStepDefinitions.i_subtract_and(int,int)"
},
"keyword": "When "
},
{
"result": {
"duration": 151000,
"status": "passed"
},
"line": 20,
"name": "The result should be 9",
"match": {
"arguments": [
{
"val": "9",
"offset": 21
}
],
"location": "hellocucumber.CalculatorStepDefinitions.the_result_should_be(int)"
},
"keyword": "Then "
}
],
"tags": [
{
"name": "@wip"
}
]
} }
], ],
"name": "Calculator", "name": "Calculator",
......
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <?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"> <testsuite errors="0" failures="0" name="io.cucumber.core.plugin.JUnitFormatter" skipped="0" tests="8" time="0.321">
<testcase classname="Calculator" name="Add two number -2 and 3" time="0.058"> <testcase classname="Calculator" name="Add two numbers -2 and 3" time="0.058">
<system-out><![CDATA[Given I have a calculator...................................................passed <system-out><![CDATA[Given I have a calculator...................................................passed
When I add -2 and 3.........................................................passed When I add -2 and 3.........................................................passed
Then The result should be 1.................................................passed Then The result should be 1.................................................passed
]]></system-out> ]]></system-out>
</testcase> </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 <system-out><![CDATA[Given I have a calculator...................................................passed
When I add 10 and 15........................................................passed When I add 10 and 15........................................................passed
Then The result should be 25................................................passed Then The result should be 25................................................passed
]]></system-out> ]]></system-out>
</testcase> </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 <system-out><![CDATA[Given I have a calculator...................................................passed
When I add 99 and -99.......................................................passed When I add 99 and -99.......................................................passed
Then The result should be 0.................................................passed Then The result should be 0.................................................passed
]]></system-out> ]]></system-out>
</testcase> </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 <system-out><![CDATA[Given I have a calculator...................................................passed
When I add -1 and -10.......................................................passed When I add -1 and -10.......................................................passed
Then The result should be -11...............................................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> ]]></system-out>
</testcase> </testcase>
</testsuite> </testsuite>
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
Feature: Calculator Feature: Calculator
As a user I want to use a calculator to add two numbers and get a total result 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 Given I have a calculator
When I add <num1> and <num2> When I add <num1> and <num2>
Then The result should be <total> Then The result should be <total>
...@@ -12,4 +12,16 @@ Feature: Calculator ...@@ -12,4 +12,16 @@ Feature: Calculator
| -2 | 3 | 1 | | -2 | 3 | 1 |
| 10 | 15 | 25 | | 10 | 15 | 25 |
| 99 | -99 | 0 | | 99 | -99 | 0 |
| -1 | -10 | -11 | | -1 | -10 | -11 |
\ No newline at end of file
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