SlideShare ist ein Scribd-Unternehmen logo
1 von 9
Getting Started with Maven and Cucumber in Eclipse
The purpose of this guide is to get the Maven and Cucumber plugins installed into eclipse and
to show how to use them to get a project started. There is plenty of documentation on how to
use the software at the command line but the plugin documentation is sorely lacking. Learn
more about Maven here- https://maven.apache.org/ and Cucumber here-
https://github.com/cucumber/cucumber-jvm.
Lets get started by installing the plugins into Eclipse. To install Maven open Eclipse and go to
Help>Install New Software. You should see this
http://download.eclipse.org/technology/m2e/releases/ this is also the same url that should be
put into the “work with” text box. You may have to restart Eclipse for the changes to take
effect. If you are having trouble, class path variables may need to be set. See here-
https://maven.apache.org/plugins/maven-eclipse-plugin/usage.html
Cucumber is just as easy to install. Use the same instructions as above however use
http://cucumber.github.com/cucumber-eclipse/update-site in the “work with” box.
We will also need some jar files to put into our project. We need to create a folder anywhere on
your hard drive to store them. There are four jars that are needed to make Cucumber run and I
added a fifth for Junit. The version numbers are the latest at this time.
cucumber-core- http://mvnrepository.com/artifact/info.cukes/cucumber-core/1.2.4
cucumber-java- http://mvnrepository.com/artifact/info.cukes/cucumber-java/1.2.4
cucumber-jvm-deps- http://mvnrepository.com/artifact/info.cukes/cucumber-jvm-deps/1.0.5
gherkin- http://mvnrepository.com/artifact/info.cukes/gherkin/2.12.2
cucumber-Junit- http://mvnrepository.com/artifact/info.cukes/cucumber-junit/1.2.4
Now we are ready to start a project. Still need Class path variables for
cucumber I think so?
Create a new Maven project. File>New>Other>Maven>Maven Project
Click finish. The Maven project is ready to add Cucumber.
Right click on your project and select New>File. Make sure it has the .feature extension.
Now we need to add the Cucumber jar files we downloaded earlier. Right Click on the project
and select Run As> Run Configurations. We are going to create a new Cucumber Feature with
the jar files we downloaded earlier. Select the Cucumber Feature on the left and create new
configuration. Give it a name and move to the Class path tab. Select your project and then click
on Add External Jars.
Go to where ever you saved those downloaded jar files select them all; then click open; then
apply; then run. You should see this:
No features found at [C:/workspace/CucumberProject/RangeTestCuke.feature]
0 Scenarios
0 Steps
0m0.000s
Nowwe have gottento the meatof the project.Cucumberhasitsown language calledGherkin.We will
write a reallysimple scenariowithoutgoingintodetailof whatthe language means.The detailscanbe
foundinthe bookcalled “The Cucumberfor JavaBook”. It usesthe commandline forexamplesbutthe
language isthe same.Get ithere- http://it-ebooks.info/book/4927/
In our simple projectwe wanttofindarange of numbersthat isbetween20and 30. Openupthe
RangeTestCuke.featurefilewe created.Putthisin.
Feature: Range
Scenario: Find the range between 20 and 30
Given the number is less than 20
When I find the range
Then number is out of bounds
NowRun As>Configurations>CukeTester.
Your outputshouldlooklike this:
You can implement missing steps with the snippets below:
@Given("^the number is less than (d+)$")
public void the_number_is_less_than(int arg1) throws Throwable {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
@When("^I find the range$")
public void i_find_the_range() throws Throwable {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
@Then("^number is out of bounds$")
public void number_is_out_of_bounds() throws Throwable {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
Great! Nowwe are readyto start writingsome code.
In yourprojectcreate a newclassinthe src/main/javafoldercalledRangeTest.
Copy the snippet into the new RangeTest.java
import cucumber.api.java.en.*;
import cucumber.api.PendingException;
public class RangeTest {
@Given("^the number is less than (d+)$")
public void the_number_is_less_than(int arg1) throws Throwable {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
@When("^I find the range$")
public void i_find_the_range() throws Throwable {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
@Then("^number is out of bounds$")
public void number_is_out_of_bounds() throws Throwable {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
}
Thiswill give usnewoutput:
Feature: Range
Scenario: Find the range between 20 and 30 #
C:/workspace/CucumberProject/RangeTestCuke.feature:2
Given the number is less than 20 # RangeTest.the_number_is_less_than(int)
cucumber.api.PendingException: TODO: implement me
at RangeTest.the_number_is_less_than(RangeTest.java:10)
at ?.Given the number is less than
20(C:/workspace/CucumberProject/RangeTestCuke.feature:3)
When I find the range # RangeTest.i_find_the_range()
Then number is out of bounds # RangeTest.number_is_out_of_bounds()
1 Scenarios (1 pending)
3 Steps (2 skipped, 1 pending)
0m0.184s
cucumber.api.PendingException: TODO: implement me
at RangeTest.the_number_is_less_than(RangeTest.java:10)
at ?.Given the number is less than
20(C:/workspace/CucumberProject/RangeTestCuke.feature:3)
Lets write some code for the first step:
@Given("^the number is less than (d+)$")
public void the_number_is_less_than(int number) throws Throwable {
int rangeNumber = number; // Write code here that turns the phrase above
into concrete actions
// throw new PendingException();
}
Run the cuke testagain:
1 Scenarios (1 pending)
3 Steps (1 skipped, 1 pending, 1 passed)
0m0.087s
The firststephas nowpassed!Twomore to go.
@When("^I find the range$")
public void i_find_the_range() throws Throwable {
int number = rangeNumber; // Write code here that turns the phrase above into
concrete actions
// throw new PendingException();
}
@Then("^number is out of bounds$")
public void number_is_out_of_bounds() throws Throwable {
if (rangeNumber<20) // Write code here that turns the phrase above into
concrete actions
System.out.println("Number is out of bounds");
// throw new PendingException();
}
Feature: Range
Number is out of bounds
Scenario: Find the range between 20 and 30 #
C:/workspace/CucumberProject/RangeTestCuke.feature:2
Given the number is less than 20 # RangeTest.the_number_is_less_than(int)
When I find the range # RangeTest.i_find_the_range()
Then number is out of bounds # RangeTest.number_is_out_of_bounds()
1 Scenarios (1 passed)
3 Steps (3 passed)
0m0.073s
It all passed.Keepinmindthisisa very simple testusedonlyforanexample.Here isthe full javacode-
import cucumber.api.java.en.*;
import cucumber.api.PendingException;
public class RangeTest {
int number = 7;
int rangeNumber=0;
@Given("^the number is less than (d+)$")
public void the_number_is_less_than(int number) throws Throwable {
int rangeNumber = number; // Write code here that turns the phrase above
into concrete actions
return;
// throw new PendingException();
}
@When("^I find the range$")
public void i_find_the_range() throws Throwable {
int number = rangeNumber; // Write code here that turns the phrase above into
concrete actions
// throw new PendingException();
}
@Then("^number is out of bounds$")
public void number_is_out_of_bounds() throws Throwable {
if (rangeNumber<20) // Write code here that turns the phrase above into
concrete actions
System.out.println("Number is out of bounds");
// throw new PendingException();
}
}
Sources
https://maven.apache.org/
The Cucumberfor JavaBook by SebRose,Matt Wynne,andAslakHellesoy
http://it-ebooks.info/book/4927/
https://books.sonatype.com/m2eclipse-book/reference/introduction-sect-m2eclipse.html
http://www.tutorialspoint.com/maven/maven_eclispe_ide.htm
Tom Arend

Weitere ähnliche Inhalte

Was ist angesagt?

Puppet camp chicago-automated_testing2
Puppet camp chicago-automated_testing2Puppet camp chicago-automated_testing2
Puppet camp chicago-automated_testing2nottings
 
AngularJS Unit Testing w/Karma and Jasmine
AngularJS Unit Testing w/Karma and JasmineAngularJS Unit Testing w/Karma and Jasmine
AngularJS Unit Testing w/Karma and Jasminefoxp2code
 
Effective Java with Groovy - How Language Influences Adoption of Good Practices
Effective Java with Groovy - How Language Influences Adoption of Good PracticesEffective Java with Groovy - How Language Influences Adoption of Good Practices
Effective Java with Groovy - How Language Influences Adoption of Good PracticesNaresha K
 
How To Test Everything
How To Test EverythingHow To Test Everything
How To Test Everythingnoelrap
 
Javascript Testing with Jasmine 101
Javascript Testing with Jasmine 101Javascript Testing with Jasmine 101
Javascript Testing with Jasmine 101Roy Yu
 
Test-Driven Development of AngularJS Applications
Test-Driven Development of AngularJS ApplicationsTest-Driven Development of AngularJS Applications
Test-Driven Development of AngularJS ApplicationsFITC
 
Angular server-side communication
Angular server-side communicationAngular server-side communication
Angular server-side communicationAlexe Bogdan
 
Testing Javascript with Jasmine
Testing Javascript with JasmineTesting Javascript with Jasmine
Testing Javascript with JasmineTim Tyrrell
 
Jasmine - why JS tests don't smell fishy
Jasmine - why JS tests don't smell fishyJasmine - why JS tests don't smell fishy
Jasmine - why JS tests don't smell fishyIgor Napierala
 
Redux Thunk - Fu - Fighting with Async
Redux Thunk - Fu - Fighting with AsyncRedux Thunk - Fu - Fighting with Async
Redux Thunk - Fu - Fighting with AsyncArtur Szott
 
Advanced Jasmine - Front-End JavaScript Unit Testing
Advanced Jasmine - Front-End JavaScript Unit TestingAdvanced Jasmine - Front-End JavaScript Unit Testing
Advanced Jasmine - Front-End JavaScript Unit TestingLars Thorup
 
AngularJS Unit Testing
AngularJS Unit TestingAngularJS Unit Testing
AngularJS Unit TestingPrince Norin
 
Intro to testing Javascript with jasmine
Intro to testing Javascript with jasmineIntro to testing Javascript with jasmine
Intro to testing Javascript with jasmineTimothy Oxley
 
Laravel Design Patterns
Laravel Design PatternsLaravel Design Patterns
Laravel Design PatternsBobby Bouwmann
 
Puppet: What _not_ to do
Puppet: What _not_ to doPuppet: What _not_ to do
Puppet: What _not_ to doPuppet
 
PowerShell: Automation for everyone
PowerShell: Automation for everyonePowerShell: Automation for everyone
PowerShell: Automation for everyoneGavin Barron
 
Symfony 4 Workshop - Limenius
Symfony 4 Workshop - LimeniusSymfony 4 Workshop - Limenius
Symfony 4 Workshop - LimeniusIgnacio Martín
 

Was ist angesagt? (20)

Getting Testy With Perl6
Getting Testy With Perl6Getting Testy With Perl6
Getting Testy With Perl6
 
Puppet camp chicago-automated_testing2
Puppet camp chicago-automated_testing2Puppet camp chicago-automated_testing2
Puppet camp chicago-automated_testing2
 
Unit Testing Lots of Perl
Unit Testing Lots of PerlUnit Testing Lots of Perl
Unit Testing Lots of Perl
 
AngularJS Unit Testing w/Karma and Jasmine
AngularJS Unit Testing w/Karma and JasmineAngularJS Unit Testing w/Karma and Jasmine
AngularJS Unit Testing w/Karma and Jasmine
 
Effective Java with Groovy - How Language Influences Adoption of Good Practices
Effective Java with Groovy - How Language Influences Adoption of Good PracticesEffective Java with Groovy - How Language Influences Adoption of Good Practices
Effective Java with Groovy - How Language Influences Adoption of Good Practices
 
How To Test Everything
How To Test EverythingHow To Test Everything
How To Test Everything
 
Jasmine BDD for Javascript
Jasmine BDD for JavascriptJasmine BDD for Javascript
Jasmine BDD for Javascript
 
Javascript Testing with Jasmine 101
Javascript Testing with Jasmine 101Javascript Testing with Jasmine 101
Javascript Testing with Jasmine 101
 
Test-Driven Development of AngularJS Applications
Test-Driven Development of AngularJS ApplicationsTest-Driven Development of AngularJS Applications
Test-Driven Development of AngularJS Applications
 
Angular server-side communication
Angular server-side communicationAngular server-side communication
Angular server-side communication
 
Testing Javascript with Jasmine
Testing Javascript with JasmineTesting Javascript with Jasmine
Testing Javascript with Jasmine
 
Jasmine - why JS tests don't smell fishy
Jasmine - why JS tests don't smell fishyJasmine - why JS tests don't smell fishy
Jasmine - why JS tests don't smell fishy
 
Redux Thunk - Fu - Fighting with Async
Redux Thunk - Fu - Fighting with AsyncRedux Thunk - Fu - Fighting with Async
Redux Thunk - Fu - Fighting with Async
 
Advanced Jasmine - Front-End JavaScript Unit Testing
Advanced Jasmine - Front-End JavaScript Unit TestingAdvanced Jasmine - Front-End JavaScript Unit Testing
Advanced Jasmine - Front-End JavaScript Unit Testing
 
AngularJS Unit Testing
AngularJS Unit TestingAngularJS Unit Testing
AngularJS Unit Testing
 
Intro to testing Javascript with jasmine
Intro to testing Javascript with jasmineIntro to testing Javascript with jasmine
Intro to testing Javascript with jasmine
 
Laravel Design Patterns
Laravel Design PatternsLaravel Design Patterns
Laravel Design Patterns
 
Puppet: What _not_ to do
Puppet: What _not_ to doPuppet: What _not_ to do
Puppet: What _not_ to do
 
PowerShell: Automation for everyone
PowerShell: Automation for everyonePowerShell: Automation for everyone
PowerShell: Automation for everyone
 
Symfony 4 Workshop - Limenius
Symfony 4 Workshop - LimeniusSymfony 4 Workshop - Limenius
Symfony 4 Workshop - Limenius
 

Ähnlich wie Getting Started with Maven and Cucumber in Eclipse

[xp2013] Narrow Down What to Test
[xp2013] Narrow Down What to Test[xp2013] Narrow Down What to Test
[xp2013] Narrow Down What to TestZsolt Fabok
 
Unit Testing for Great Justice
Unit Testing for Great JusticeUnit Testing for Great Justice
Unit Testing for Great JusticeDomenic Denicola
 
How to test infrastructure code: automated testing for Terraform, Kubernetes,...
How to test infrastructure code: automated testing for Terraform, Kubernetes,...How to test infrastructure code: automated testing for Terraform, Kubernetes,...
How to test infrastructure code: automated testing for Terraform, Kubernetes,...Yevgeniy Brikman
 
Javascript tdd byandreapaciolla
Javascript tdd byandreapaciollaJavascript tdd byandreapaciolla
Javascript tdd byandreapaciollaAndrea Paciolla
 
Create & Execute First Hadoop MapReduce Project in.pptx
Create & Execute First Hadoop MapReduce Project in.pptxCreate & Execute First Hadoop MapReduce Project in.pptx
Create & Execute First Hadoop MapReduce Project in.pptxvishal choudhary
 
Bring the fun back to java
Bring the fun back to javaBring the fun back to java
Bring the fun back to javaciklum_ods
 
We Are All Testers Now: The Testing Pyramid and Front-End Development
We Are All Testers Now: The Testing Pyramid and Front-End DevelopmentWe Are All Testers Now: The Testing Pyramid and Front-End Development
We Are All Testers Now: The Testing Pyramid and Front-End DevelopmentAll Things Open
 
Working Effectively With Legacy Code
Working Effectively With Legacy CodeWorking Effectively With Legacy Code
Working Effectively With Legacy CodeNaresh Jain
 
Cucumber presentation
Cucumber presentationCucumber presentation
Cucumber presentationAkhila B
 
Vb script tutorial for qtp[1]
Vb script tutorial for qtp[1]Vb script tutorial for qtp[1]
Vb script tutorial for qtp[1]srikanthbkm
 
Advanced Perl Techniques
Advanced Perl TechniquesAdvanced Perl Techniques
Advanced Perl TechniquesDave Cross
 
Angularjs - Unit testing introduction
Angularjs - Unit testing introductionAngularjs - Unit testing introduction
Angularjs - Unit testing introductionNir Kaufman
 
Integrating Maven with Eclipse
Integrating Maven with EclipseIntegrating Maven with Eclipse
Integrating Maven with EclipseNikhil Bharati
 
Testing Legacy Rails Apps
Testing Legacy Rails AppsTesting Legacy Rails Apps
Testing Legacy Rails AppsRabble .
 
Cool JVM Tools to Help You Test
Cool JVM Tools to Help You TestCool JVM Tools to Help You Test
Cool JVM Tools to Help You TestSchalk Cronjé
 
Ruby on rails integration testing with minitest and capybara
Ruby on rails integration testing with minitest and capybaraRuby on rails integration testing with minitest and capybara
Ruby on rails integration testing with minitest and capybaraAndolasoft Inc
 
JavaScript - Chapter 15 - Debugging Techniques
 JavaScript - Chapter 15 - Debugging Techniques JavaScript - Chapter 15 - Debugging Techniques
JavaScript - Chapter 15 - Debugging TechniquesWebStackAcademy
 
Testing in AngularJS
Testing in AngularJSTesting in AngularJS
Testing in AngularJSPeter Drinnan
 

Ähnlich wie Getting Started with Maven and Cucumber in Eclipse (20)

[xp2013] Narrow Down What to Test
[xp2013] Narrow Down What to Test[xp2013] Narrow Down What to Test
[xp2013] Narrow Down What to Test
 
Unit Testing for Great Justice
Unit Testing for Great JusticeUnit Testing for Great Justice
Unit Testing for Great Justice
 
Cucumber with appium
Cucumber with appiumCucumber with appium
Cucumber with appium
 
How to test infrastructure code: automated testing for Terraform, Kubernetes,...
How to test infrastructure code: automated testing for Terraform, Kubernetes,...How to test infrastructure code: automated testing for Terraform, Kubernetes,...
How to test infrastructure code: automated testing for Terraform, Kubernetes,...
 
Javascript tdd byandreapaciolla
Javascript tdd byandreapaciollaJavascript tdd byandreapaciolla
Javascript tdd byandreapaciolla
 
Create & Execute First Hadoop MapReduce Project in.pptx
Create & Execute First Hadoop MapReduce Project in.pptxCreate & Execute First Hadoop MapReduce Project in.pptx
Create & Execute First Hadoop MapReduce Project in.pptx
 
Bring the fun back to java
Bring the fun back to javaBring the fun back to java
Bring the fun back to java
 
We Are All Testers Now: The Testing Pyramid and Front-End Development
We Are All Testers Now: The Testing Pyramid and Front-End DevelopmentWe Are All Testers Now: The Testing Pyramid and Front-End Development
We Are All Testers Now: The Testing Pyramid and Front-End Development
 
Working Effectively With Legacy Code
Working Effectively With Legacy CodeWorking Effectively With Legacy Code
Working Effectively With Legacy Code
 
Cucumber presentation
Cucumber presentationCucumber presentation
Cucumber presentation
 
Vb script tutorial for qtp[1]
Vb script tutorial for qtp[1]Vb script tutorial for qtp[1]
Vb script tutorial for qtp[1]
 
Advanced Perl Techniques
Advanced Perl TechniquesAdvanced Perl Techniques
Advanced Perl Techniques
 
Angularjs - Unit testing introduction
Angularjs - Unit testing introductionAngularjs - Unit testing introduction
Angularjs - Unit testing introduction
 
Integrating Maven with Eclipse
Integrating Maven with EclipseIntegrating Maven with Eclipse
Integrating Maven with Eclipse
 
Testing Legacy Rails Apps
Testing Legacy Rails AppsTesting Legacy Rails Apps
Testing Legacy Rails Apps
 
Java Quiz - Meetup
Java Quiz - MeetupJava Quiz - Meetup
Java Quiz - Meetup
 
Cool JVM Tools to Help You Test
Cool JVM Tools to Help You TestCool JVM Tools to Help You Test
Cool JVM Tools to Help You Test
 
Ruby on rails integration testing with minitest and capybara
Ruby on rails integration testing with minitest and capybaraRuby on rails integration testing with minitest and capybara
Ruby on rails integration testing with minitest and capybara
 
JavaScript - Chapter 15 - Debugging Techniques
 JavaScript - Chapter 15 - Debugging Techniques JavaScript - Chapter 15 - Debugging Techniques
JavaScript - Chapter 15 - Debugging Techniques
 
Testing in AngularJS
Testing in AngularJSTesting in AngularJS
Testing in AngularJS
 

Getting Started with Maven and Cucumber in Eclipse

  • 1. Getting Started with Maven and Cucumber in Eclipse The purpose of this guide is to get the Maven and Cucumber plugins installed into eclipse and to show how to use them to get a project started. There is plenty of documentation on how to use the software at the command line but the plugin documentation is sorely lacking. Learn more about Maven here- https://maven.apache.org/ and Cucumber here- https://github.com/cucumber/cucumber-jvm. Lets get started by installing the plugins into Eclipse. To install Maven open Eclipse and go to Help>Install New Software. You should see this http://download.eclipse.org/technology/m2e/releases/ this is also the same url that should be put into the “work with” text box. You may have to restart Eclipse for the changes to take effect. If you are having trouble, class path variables may need to be set. See here- https://maven.apache.org/plugins/maven-eclipse-plugin/usage.html Cucumber is just as easy to install. Use the same instructions as above however use http://cucumber.github.com/cucumber-eclipse/update-site in the “work with” box. We will also need some jar files to put into our project. We need to create a folder anywhere on your hard drive to store them. There are four jars that are needed to make Cucumber run and I added a fifth for Junit. The version numbers are the latest at this time. cucumber-core- http://mvnrepository.com/artifact/info.cukes/cucumber-core/1.2.4 cucumber-java- http://mvnrepository.com/artifact/info.cukes/cucumber-java/1.2.4 cucumber-jvm-deps- http://mvnrepository.com/artifact/info.cukes/cucumber-jvm-deps/1.0.5 gherkin- http://mvnrepository.com/artifact/info.cukes/gherkin/2.12.2 cucumber-Junit- http://mvnrepository.com/artifact/info.cukes/cucumber-junit/1.2.4 Now we are ready to start a project. Still need Class path variables for cucumber I think so?
  • 2. Create a new Maven project. File>New>Other>Maven>Maven Project
  • 3. Click finish. The Maven project is ready to add Cucumber.
  • 4. Right click on your project and select New>File. Make sure it has the .feature extension. Now we need to add the Cucumber jar files we downloaded earlier. Right Click on the project and select Run As> Run Configurations. We are going to create a new Cucumber Feature with the jar files we downloaded earlier. Select the Cucumber Feature on the left and create new configuration. Give it a name and move to the Class path tab. Select your project and then click on Add External Jars.
  • 5. Go to where ever you saved those downloaded jar files select them all; then click open; then apply; then run. You should see this: No features found at [C:/workspace/CucumberProject/RangeTestCuke.feature] 0 Scenarios 0 Steps 0m0.000s Nowwe have gottento the meatof the project.Cucumberhasitsown language calledGherkin.We will write a reallysimple scenariowithoutgoingintodetailof whatthe language means.The detailscanbe foundinthe bookcalled “The Cucumberfor JavaBook”. It usesthe commandline forexamplesbutthe language isthe same.Get ithere- http://it-ebooks.info/book/4927/
  • 6. In our simple projectwe wanttofindarange of numbersthat isbetween20and 30. Openupthe RangeTestCuke.featurefilewe created.Putthisin. Feature: Range Scenario: Find the range between 20 and 30 Given the number is less than 20 When I find the range Then number is out of bounds NowRun As>Configurations>CukeTester. Your outputshouldlooklike this: You can implement missing steps with the snippets below: @Given("^the number is less than (d+)$") public void the_number_is_less_than(int arg1) throws Throwable { // Write code here that turns the phrase above into concrete actions throw new PendingException(); } @When("^I find the range$") public void i_find_the_range() throws Throwable { // Write code here that turns the phrase above into concrete actions throw new PendingException(); } @Then("^number is out of bounds$") public void number_is_out_of_bounds() throws Throwable { // Write code here that turns the phrase above into concrete actions throw new PendingException(); } Great! Nowwe are readyto start writingsome code. In yourprojectcreate a newclassinthe src/main/javafoldercalledRangeTest. Copy the snippet into the new RangeTest.java import cucumber.api.java.en.*; import cucumber.api.PendingException; public class RangeTest { @Given("^the number is less than (d+)$") public void the_number_is_less_than(int arg1) throws Throwable { // Write code here that turns the phrase above into concrete actions throw new PendingException(); }
  • 7. @When("^I find the range$") public void i_find_the_range() throws Throwable { // Write code here that turns the phrase above into concrete actions throw new PendingException(); } @Then("^number is out of bounds$") public void number_is_out_of_bounds() throws Throwable { // Write code here that turns the phrase above into concrete actions throw new PendingException(); } } Thiswill give usnewoutput: Feature: Range Scenario: Find the range between 20 and 30 # C:/workspace/CucumberProject/RangeTestCuke.feature:2 Given the number is less than 20 # RangeTest.the_number_is_less_than(int) cucumber.api.PendingException: TODO: implement me at RangeTest.the_number_is_less_than(RangeTest.java:10) at ?.Given the number is less than 20(C:/workspace/CucumberProject/RangeTestCuke.feature:3) When I find the range # RangeTest.i_find_the_range() Then number is out of bounds # RangeTest.number_is_out_of_bounds() 1 Scenarios (1 pending) 3 Steps (2 skipped, 1 pending) 0m0.184s cucumber.api.PendingException: TODO: implement me at RangeTest.the_number_is_less_than(RangeTest.java:10) at ?.Given the number is less than 20(C:/workspace/CucumberProject/RangeTestCuke.feature:3) Lets write some code for the first step: @Given("^the number is less than (d+)$") public void the_number_is_less_than(int number) throws Throwable { int rangeNumber = number; // Write code here that turns the phrase above into concrete actions // throw new PendingException(); }
  • 8. Run the cuke testagain: 1 Scenarios (1 pending) 3 Steps (1 skipped, 1 pending, 1 passed) 0m0.087s The firststephas nowpassed!Twomore to go. @When("^I find the range$") public void i_find_the_range() throws Throwable { int number = rangeNumber; // Write code here that turns the phrase above into concrete actions // throw new PendingException(); } @Then("^number is out of bounds$") public void number_is_out_of_bounds() throws Throwable { if (rangeNumber<20) // Write code here that turns the phrase above into concrete actions System.out.println("Number is out of bounds"); // throw new PendingException(); } Feature: Range Number is out of bounds Scenario: Find the range between 20 and 30 # C:/workspace/CucumberProject/RangeTestCuke.feature:2 Given the number is less than 20 # RangeTest.the_number_is_less_than(int) When I find the range # RangeTest.i_find_the_range() Then number is out of bounds # RangeTest.number_is_out_of_bounds() 1 Scenarios (1 passed) 3 Steps (3 passed) 0m0.073s It all passed.Keepinmindthisisa very simple testusedonlyforanexample.Here isthe full javacode- import cucumber.api.java.en.*; import cucumber.api.PendingException; public class RangeTest {
  • 9. int number = 7; int rangeNumber=0; @Given("^the number is less than (d+)$") public void the_number_is_less_than(int number) throws Throwable { int rangeNumber = number; // Write code here that turns the phrase above into concrete actions return; // throw new PendingException(); } @When("^I find the range$") public void i_find_the_range() throws Throwable { int number = rangeNumber; // Write code here that turns the phrase above into concrete actions // throw new PendingException(); } @Then("^number is out of bounds$") public void number_is_out_of_bounds() throws Throwable { if (rangeNumber<20) // Write code here that turns the phrase above into concrete actions System.out.println("Number is out of bounds"); // throw new PendingException(); } } Sources https://maven.apache.org/ The Cucumberfor JavaBook by SebRose,Matt Wynne,andAslakHellesoy http://it-ebooks.info/book/4927/ https://books.sonatype.com/m2eclipse-book/reference/introduction-sect-m2eclipse.html http://www.tutorialspoint.com/maven/maven_eclispe_ide.htm Tom Arend