re-organize testing modules
This commit is contained in:
+14
@@ -0,0 +1,14 @@
|
||||
package com.baeldung.calculator;
|
||||
|
||||
import cucumber.api.CucumberOptions;
|
||||
import cucumber.api.junit.Cucumber;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@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 CalculatorIntegrationTest {
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
package com.baeldung.calculator;
|
||||
|
||||
import com.baeldung.cucumber.Calculator;
|
||||
import cucumber.api.java.Before;
|
||||
import cucumber.api.java.en.Given;
|
||||
import cucumber.api.java.en.Then;
|
||||
import cucumber.api.java.en.When;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.Assert;
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
}
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
package com.baeldung.lambdabehave;
|
||||
|
||||
import com.insightfullogic.lambdabehave.JunitSuiteRunner;
|
||||
import com.insightfullogic.lambdabehave.Suite;
|
||||
import com.insightfullogic.lambdabehave.generators.Generator;
|
||||
import com.insightfullogic.lambdabehave.generators.SourceGenerator;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@RunWith(JunitSuiteRunner.class)
|
||||
public class CalculatorUnitTest {
|
||||
|
||||
private Calculator calculator;
|
||||
|
||||
{
|
||||
Suite.describe("Lambda behave example tests", it -> {
|
||||
|
||||
it.isSetupWith(() -> {
|
||||
calculator = new Calculator(1, 2);
|
||||
});
|
||||
it.should("Add the given numbers", expect -> {
|
||||
expect.that(calculator.add()).is(3);
|
||||
});
|
||||
it.should("Throw an exception if divide by 0", expect -> {
|
||||
expect.exception(ArithmeticException.class, () -> {
|
||||
calculator.divide(1, 0);
|
||||
});
|
||||
});
|
||||
it.uses(2, 3, 5)
|
||||
.and(23, 10, 33)
|
||||
.toShow("%d + %d = %d", (expect, a, b, c) -> {
|
||||
expect.that(calculator.add(a, b)).is(c);
|
||||
});
|
||||
it.requires(2)
|
||||
.example(Generator.asciiStrings())
|
||||
.toShow("Reversing a String twice returns the original String", (expect, str) -> {
|
||||
String same = new StringBuilder(str).reverse()
|
||||
.reverse()
|
||||
.toString();
|
||||
expect.that(same)
|
||||
.isEqualTo(str);
|
||||
});
|
||||
it.requires(2)
|
||||
.withSource(SourceGenerator.deterministicNumbers(5626689007407L))
|
||||
.example(Generator.asciiStrings())
|
||||
.toShow("Reversing a String twice returns the original String", (expect, str) -> {
|
||||
String same = new StringBuilder(str).reverse()
|
||||
.reverse()
|
||||
.toString();
|
||||
expect.that(same)
|
||||
.isEqualTo(str);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
package com.baeldung.mutation;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.baeldung.mutation.Palindrome;
|
||||
|
||||
public class PalindromeUnitTest {
|
||||
@Test
|
||||
public void whenEmptyString_thanAccept() {
|
||||
Palindrome palindromeTester = new Palindrome();
|
||||
assertTrue(palindromeTester.isPalindrome("noon"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenPalindrom_thanAccept() {
|
||||
Palindrome palindromeTester = new Palindrome();
|
||||
assertTrue(palindromeTester.isPalindrome("noon"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenNotPalindrom_thanReject(){
|
||||
Palindrome palindromeTester = new Palindrome();
|
||||
assertFalse(palindromeTester.isPalindrome("box"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenNearPalindrom_thanReject(){
|
||||
Palindrome palindromeTester = new Palindrome();
|
||||
assertFalse(palindromeTester.isPalindrome("neon"));
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package com.baeldung.shopping;
|
||||
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import cucumber.api.CucumberOptions;
|
||||
import cucumber.api.junit.Cucumber;
|
||||
|
||||
@RunWith(Cucumber.class)
|
||||
@CucumberOptions(features = { "classpath:features/shopping.feature" })
|
||||
public class ShoppingIntegrationTest {
|
||||
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
package com.baeldung.shopping;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import cucumber.api.java8.En;
|
||||
|
||||
public class ShoppingStepsDef implements En {
|
||||
|
||||
private int budget = 0;
|
||||
|
||||
public ShoppingStepsDef() {
|
||||
|
||||
Given("I have (\\d+) in my wallet", (Integer money) -> budget = money);
|
||||
|
||||
When("I buy .* with (\\d+)", (Integer price) -> budget -= price);
|
||||
|
||||
Then("I should have (\\d+) in my wallet", (Integer finalBudget) -> {
|
||||
assertEquals(budget, finalBudget.intValue());
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+16
@@ -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,11 @@
|
||||
Feature: Shopping
|
||||
|
||||
Scenario: Track my budget
|
||||
Given I have 100 in my wallet
|
||||
When I buy milk with 10
|
||||
Then I should have 90 in my wallet
|
||||
|
||||
Scenario: Track my budget
|
||||
Given I have 200 in my wallet
|
||||
When I buy rice with 20
|
||||
Then I should have 180 in my wallet
|
||||
Reference in New Issue
Block a user