Commit 8118d3ec authored by Kyle Muldoon's avatar Kyle Muldoon

added tests + results for a basic calculator

parent fddd302e
package hellocucumber;
public class Calculator {
public Integer add(Integer l, Integer r) {
int x = l + r;
return x; }
// public Long subtract(Long l, Long r) { return l - r; }
// public Long multiply(Long l, Long r) { return l * r; }
// public Long divide(Long l, Long r) { return l / r; }
}
package hellocucumber;
import io.cucumber.java.en.Given;
import io.cucumber.java.en.When;
import io.cucumber.java.en.Then;
import static org.junit.Assert.*;
public class CalculatorSteps {
Calculator calculator;
Integer result;
@Given("^I have a calculator$")
public void generateCalculator() {
this.calculator = new Calculator();
}
@When("I add {int} and {int}")
public void addUsingCalculator (Integer l, Integer r) {
this.result = this.calculator.add(l, r);
}
@Then("the result should be {int}")
public void checkResult(Integer res) {
assertEquals(this.result, res);
}
}
......@@ -5,7 +5,14 @@ import io.cucumber.junit.CucumberOptions;
import org.junit.runner.RunWith;
@RunWith(Cucumber.class)
@CucumberOptions(plugin = {"pretty"})
public class RunCucumberTest {
}
@CucumberOptions(
plugin = {
"pretty",
"html:target/surefire-reports/report.html",
"json:target/surefire-reports/json/report.json",
"junit:target/surefire-reports/junit/report.xml"
} //,
//tags = "@wip" // only runs things with the @wip tag. Can also do "not @wip" for opposite effect
// monochrome = true // console output will keep the same lightened color (including comments)
)
public class RunCucumberTest { }
Feature: Does my simple calculator work properly?
Everybody wants a functioning calculator
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 |
/Users/kmuldoon/Dev/practice/testing/cucumber/hellocucumber/src/test/java/hellocucumber/RunCucumberTest.java
/Users/kmuldoon/Dev/practice/testing/cucumber/hellocucumber/src/test/java/hellocucumber/Calculator.java
/Users/kmuldoon/Dev/practice/testing/cucumber/hellocucumber/src/test/java/hellocucumber/StepDefinitions.java
/Users/kmuldoon/Dev/practice/testing/cucumber/hellocucumber/src/test/java/hellocucumber/CalculatorSteps.java
<?xml version="1.0" encoding="UTF-8" ?>
<testsuite tests="2" failures="0" name="hellocucumber.RunCucumberTest" time="0.163" errors="0" skipped="0">
<testsuite tests="6" failures="0" name="hellocucumber.RunCucumberTest" time="0.228" errors="0" skipped="0">
<properties>
<property name="java.runtime.name" value="OpenJDK Runtime Environment"/>
<property name="java.vm.version" value="15.0.2+7"/>
......@@ -34,7 +34,7 @@
<property name="library.jansi.path" value="/usr/local/Cellar/maven/3.6.3_1/libexec/lib/jansi-native"/>
<property name="http.nonProxyHosts" value="local|*.local|169.254/16|*.169.254/16"/>
<property name="user.home" value="/Users/kmuldoon"/>
<property name="user.timezone" value="America/Chicago"/>
<property name="user.timezone" value="America/Los_Angeles"/>
<property name="file.encoding" value="UTF-8"/>
<property name="java.specification.version" value="15"/>
<property name="user.name" value="kmuldoon"/>
......@@ -57,6 +57,10 @@
<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="Is it Friday yet?" name="Sunday isn&apos;t Friday" time="0.16"/>
<testcase classname="Is it Friday yet?" name="Friday is Friday" time="0.003"/>
<testcase classname="Does my simple calculator work properly?" name="Add two numbers -2 &amp; 3" time="0.17"/>
<testcase classname="Does my simple calculator work properly?" name="Add two numbers 10 &amp; 15" time="0.013"/>
<testcase classname="Does my simple calculator work properly?" name="Add two numbers 99 &amp; -99" time="0.014"/>
<testcase classname="Does my simple calculator work properly?" name="Add two numbers -1 &amp; -10" time="0.009"/>
<testcase classname="Is it Friday yet?" name="Sunday isn&apos;t Friday" time="0.009"/>
<testcase classname="Is it Friday yet?" name="Friday is Friday" time="0.013"/>
</testsuite>
\ No newline at end of file
-------------------------------------------------------------------------------
Test set: hellocucumber.RunCucumberTest
-------------------------------------------------------------------------------
Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.463 sec
Tests run: 6, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.011 sec
[
{
"line": 1,
"elements": [
{
"start_timestamp": "2021-04-06T20:09:53.013Z",
"line": 11,
"name": "Add two numbers -2 \u0026 3",
"description": "",
"id": "does-my-simple-calculator-work-properly?;add-two-numbers-\u003cnum1\u003e-\u0026-\u003cnum2\u003e;;2",
"type": "scenario",
"keyword": "Scenario Outline",
"steps": [
{
"result": {
"duration": 1471000,
"status": "passed"
},
"line": 5,
"name": "I have a calculator",
"match": {
"location": "hellocucumber.CalculatorSteps.generateCalculator()"
},
"keyword": "Given "
},
{
"result": {
"duration": 530000,
"status": "passed"
},
"line": 6,
"name": "I add -2 and 3",
"match": {
"arguments": [
{
"val": "-2",
"offset": 6
},
{
"val": "3",
"offset": 13
}
],
"location": "hellocucumber.CalculatorSteps.addUsingCalculator(java.lang.Integer,java.lang.Integer)"
},
"keyword": "When "
},
{
"result": {
"duration": 1158000,
"status": "passed"
},
"line": 7,
"name": "the result should be 1",
"match": {
"arguments": [
{
"val": "1",
"offset": 21
}
],
"location": "hellocucumber.CalculatorSteps.checkResult(java.lang.Integer)"
},
"keyword": "Then "
}
]
},
{
"start_timestamp": "2021-04-06T20:09:53.083Z",
"line": 12,
"name": "Add two numbers 10 \u0026 15",
"description": "",
"id": "does-my-simple-calculator-work-properly?;add-two-numbers-\u003cnum1\u003e-\u0026-\u003cnum2\u003e;;3",
"type": "scenario",
"keyword": "Scenario Outline",
"steps": [
{
"result": {
"duration": 175000,
"status": "passed"
},
"line": 5,
"name": "I have a calculator",
"match": {
"location": "hellocucumber.CalculatorSteps.generateCalculator()"
},
"keyword": "Given "
},
{
"result": {
"duration": 290000,
"status": "passed"
},
"line": 6,
"name": "I add 10 and 15",
"match": {
"arguments": [
{
"val": "10",
"offset": 6
},
{
"val": "15",
"offset": 13
}
],
"location": "hellocucumber.CalculatorSteps.addUsingCalculator(java.lang.Integer,java.lang.Integer)"
},
"keyword": "When "
},
{
"result": {
"duration": 396000,
"status": "passed"
},
"line": 7,
"name": "the result should be 25",
"match": {
"arguments": [
{
"val": "25",
"offset": 21
}
],
"location": "hellocucumber.CalculatorSteps.checkResult(java.lang.Integer)"
},
"keyword": "Then "
}
]
},
{
"start_timestamp": "2021-04-06T20:09:53.094Z",
"line": 13,
"name": "Add two numbers 99 \u0026 -99",
"description": "",
"id": "does-my-simple-calculator-work-properly?;add-two-numbers-\u003cnum1\u003e-\u0026-\u003cnum2\u003e;;4",
"type": "scenario",
"keyword": "Scenario Outline",
"steps": [
{
"result": {
"duration": 259000,
"status": "passed"
},
"line": 5,
"name": "I have a calculator",
"match": {
"location": "hellocucumber.CalculatorSteps.generateCalculator()"
},
"keyword": "Given "
},
{
"result": {
"duration": 920000,
"status": "passed"
},
"line": 6,
"name": "I add 99 and -99",
"match": {
"arguments": [
{
"val": "99",
"offset": 6
},
{
"val": "-99",
"offset": 13
}
],
"location": "hellocucumber.CalculatorSteps.addUsingCalculator(java.lang.Integer,java.lang.Integer)"
},
"keyword": "When "
},
{
"result": {
"duration": 272000,
"status": "passed"
},
"line": 7,
"name": "the result should be 0",
"match": {
"arguments": [
{
"val": "0",
"offset": 21
}
],
"location": "hellocucumber.CalculatorSteps.checkResult(java.lang.Integer)"
},
"keyword": "Then "
}
]
},
{
"start_timestamp": "2021-04-06T20:09:53.106Z",
"line": 14,
"name": "Add two numbers -1 \u0026 -10",
"description": "",
"id": "does-my-simple-calculator-work-properly?;add-two-numbers-\u003cnum1\u003e-\u0026-\u003cnum2\u003e;;5",
"type": "scenario",
"keyword": "Scenario Outline",
"steps": [
{
"result": {
"duration": 215000,
"status": "passed"
},
"line": 5,
"name": "I have a calculator",
"match": {
"location": "hellocucumber.CalculatorSteps.generateCalculator()"
},
"keyword": "Given "
},
{
"result": {
"duration": 236000,
"status": "passed"
},
"line": 6,
"name": "I add -1 and -10",
"match": {
"arguments": [
{
"val": "-1",
"offset": 6
},
{
"val": "-10",
"offset": 13
}
],
"location": "hellocucumber.CalculatorSteps.addUsingCalculator(java.lang.Integer,java.lang.Integer)"
},
"keyword": "When "
},
{
"result": {
"duration": 214000,
"status": "passed"
},
"line": 7,
"name": "the result should be -11",
"match": {
"arguments": [
{
"val": "-11",
"offset": 21
}
],
"location": "hellocucumber.CalculatorSteps.checkResult(java.lang.Integer)"
},
"keyword": "Then "
}
]
}
],
"name": "Does my simple calculator work properly?",
"description": " Everybody wants a functioning calculator",
"id": "does-my-simple-calculator-work-properly?",
"keyword": "Feature",
"uri": "classpath:hellocucumber/calculatorTests.feature",
"tags": []
},
{
"line": 1,
"elements": [
{
"start_timestamp": "2021-04-06T20:09:53.113Z",
"line": 4,
"name": "Sunday isn\u0027t Friday",
"description": "",
"id": "is-it-friday-yet?;sunday-isn-t-friday",
"type": "scenario",
"keyword": "Scenario",
"steps": [
{
"result": {
"duration": 143000,
"status": "passed"
},
"line": 5,
"name": "today is Sunday",
"match": {
"location": "hellocucumber.StepDefinitions.today_is_Sunday()"
},
"keyword": "Given "
},
{
"result": {
"duration": 126000,
"status": "passed"
},
"line": 6,
"name": "I ask whether it\u0027s Friday yet",
"match": {
"location": "hellocucumber.StepDefinitions.i_ask_whether_it_s_Friday_yet()"
},
"keyword": "When "
},
{
"result": {
"duration": 249000,
"status": "passed"
},
"line": 7,
"name": "I should be told \"Nope\"",
"match": {
"arguments": [
{
"val": "\"Nope\"",
"offset": 17
}
],
"location": "hellocucumber.StepDefinitions.i_should_be_told(java.lang.String)"
},
"keyword": "Then "
}
]
},
{
"start_timestamp": "2021-04-06T20:09:53.125Z",
"line": 9,
"name": "Friday is Friday",
"description": "",
"id": "is-it-friday-yet?;friday-is-friday",
"type": "scenario",
"keyword": "Scenario",
"steps": [
{
"result": {
"duration": 664000,
"status": "passed"
},
"line": 10,
"name": "today is Friday",
"match": {
"location": "hellocucumber.StepDefinitions.today_is_Friday()"
},
"keyword": "Given "
},
{
"result": {
"duration": 220000,
"status": "passed"
},
"line": 11,
"name": "I ask whether it\u0027s Friday yet",
"match": {
"location": "hellocucumber.StepDefinitions.i_ask_whether_it_s_Friday_yet()"
},
"keyword": "When "
},
{
"result": {
"duration": 250000,
"status": "passed"
},
"line": 12,
"name": "I should be told \"TGIF\"",
"match": {
"arguments": [
{
"val": "\"TGIF\"",
"offset": 17
}
],
"location": "hellocucumber.StepDefinitions.i_should_be_told(java.lang.String)"
},
"keyword": "Then "
}
]
}
],
"name": "Is it Friday yet?",
"description": " Everybody wants to know when it\u0027s Friday",
"id": "is-it-friday-yet?",
"keyword": "Feature",
"uri": "classpath:hellocucumber/is_it_friday_yet.feature",
"tags": []
}
]
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<testsuite errors="0" failures="0" name="io.cucumber.core.plugin.JUnitFormatter" skipped="0" tests="6" time="0.255">
<testcase classname="Does my simple calculator work properly?" name="Add two numbers -2 &amp; 3" time="0.052">
<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="Does my simple calculator work properly?" name="Add two numbers 10 &amp; 15" time="0.002">
<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="Does my simple calculator work properly?" name="Add two numbers 99 &amp; -99" time="0.005">
<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="Does my simple calculator work properly?" name="Add two numbers -1 &amp; -10" time="0.002">
<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="Is it Friday yet?" name="Sunday isn't Friday" time="0.003">
<system-out><![CDATA[Given today is Sunday.......................................................passed
When I ask whether it's Friday yet..........................................passed
Then I should be told "Nope"................................................passed
]]></system-out>
</testcase>
<testcase classname="Is it Friday yet?" name="Friday is Friday" time="0.005">
<system-out><![CDATA[Given today is Friday.......................................................passed
When I ask whether it's Friday yet..........................................passed
Then I should be told "TGIF"................................................passed
]]></system-out>
</testcase>
</testsuite>
This source diff could not be displayed because it is too large. You can view the blob instead.
Feature: Does my simple calculator work properly?
Everybody wants a functioning calculator
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 |
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