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
This diff is collapsed.
<?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 diff is collapsed.
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