├── BehaviourDrivenDevelopment ├── pom.xml └── src │ ├── main │ └── java │ │ └── lk │ │ └── himash │ │ └── controller │ │ └── DiscountController.java │ ├── offer.feature │ └── test │ └── java │ └── DiscountControllerTest.java └── README.md /BehaviourDrivenDevelopment/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | lk.himash 8 | BehaviourDrivenDevelopment 9 | 1.0-SNAPSHOT 10 | 11 | 12 | 11 13 | 11 14 | 15 | 16 | 17 | 18 | org.seleniumhq.selenium 19 | selenium-java 20 | 3.13.0 21 | 22 | 23 | junit 24 | junit 25 | 4.12 26 | test 27 | 28 | 29 | info.cukes 30 | cucumber-junit 31 | 1.2.5 32 | test 33 | 34 | 35 | info.cukes 36 | cucumber-java 37 | 1.2.5 38 | 39 | 40 | info.cukes 41 | cucumber-jvm 42 | 1.2.5 43 | pom 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /BehaviourDrivenDevelopment/src/main/java/lk/himash/controller/DiscountController.java: -------------------------------------------------------------------------------- 1 | package lk.himash.controller; 2 | 3 | public class DiscountController { 4 | 5 | public String getDiscount(int amount) { 6 | String discountPercentage = ""; 7 | if (amount > 5000 && amount < 10000) { 8 | discountPercentage = "10%"; 9 | } else if (amount > 10000) { 10 | discountPercentage = "15%"; 11 | }else { 12 | discountPercentage="NA"; 13 | } 14 | return discountPercentage; 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /BehaviourDrivenDevelopment/src/offer.feature: -------------------------------------------------------------------------------- 1 | Feature: Evaluate percentage 2 | 3 | Scenario: Verify 10% offer 4 | Given Execute DiscountController Business 5 | When if i will enter 5001 6 | Then we should get ten percentage discount 7 | 8 | Scenario: Verify 15% offer 9 | Given Execute DiscountController Business 10 | When if i will enter 11000 11 | Then we should get fifteen percentage discount 12 | 13 | Scenario: Verify No offer 14 | Given Execute DiscountController Business 15 | When if i will enter 4000 16 | Then we shouldn't get any percentage -------------------------------------------------------------------------------- /BehaviourDrivenDevelopment/src/test/java/DiscountControllerTest.java: -------------------------------------------------------------------------------- 1 | import cucumber.api.java.en.Given; 2 | import cucumber.api.java.en.Then; 3 | import cucumber.api.java.en.When; 4 | import lk.himash.controller.DiscountController; 5 | import org.junit.Assert; 6 | 7 | public class DiscountControllerTest { 8 | 9 | DiscountController discountController = null; 10 | String percentage = ""; 11 | 12 | @Given("^Execute DiscountController Business$") 13 | public void execute_DiscountController_Business() throws Throwable { 14 | 15 | } 16 | 17 | @When("^if i will enter (\\d+)$") 18 | public void if_i_will_enter(int arg1) throws Throwable { 19 | percentage = discountController.getDiscount(arg1); 20 | } 21 | 22 | @Then("^we should get ten percentage discount$") 23 | public void we_should_get_ten_percentage_discount() throws Throwable { 24 | Assert.assertEquals("10%", percentage); 25 | } 26 | 27 | @Then("^we should get fifteen percentage discount$") 28 | public void we_should_get_fifteen_percentage_discount() throws Throwable { 29 | Assert.assertEquals("15%", percentage); 30 | } 31 | 32 | @Then("^we shouldn't get any percentage$") 33 | public void we_shouldn_t_get_any_percentage() throws Throwable { 34 | Assert.assertEquals("NA", percentage); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Behaviour-driven-development 2 | Implement Behaviour driven development using Java. 3 | 4 | ## Requirements 5 | 6 | 01) Java 11 7 | 02) Maven 3.8 8 | 9 | ## Project setup 10 | 11 | 01) Clone the project 12 | 13 | https://github.com/himash79/Behavior-driven-development.git 14 | 15 | 03) Clean and build the project using maven 16 | 17 | open command line (CMD) in project directory and execute 'mvn clean install' 18 | 19 | 04) Open project using intelij / eclipse. 20 | 21 | 05) Test the senarios. 22 | --------------------------------------------------------------------------------