Behaviour-driven development and acceptance tests on Java web applications
Upcoming SlideShare
Loading in...5
×
 

Behaviour-driven development and acceptance tests on Java web applications

on

  • 4,275 views

Internal BDD talk at Giran (http://www.giran.com.br).

Internal BDD talk at Giran (http://www.giran.com.br).

Source code at: http://github.com/franciscosouza/java-bdd-talk

Statistics

Views

Total Views
4,275
Views on SlideShare
4,272
Embed Views
3

Actions

Likes
6
Downloads
145
Comments
0

2 Embeds 3

http://www.franciscosouza.net 2
http://www.linkedin.com 1

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

CC Attribution-NonCommercial-ShareAlike LicenseCC Attribution-NonCommercial-ShareAlike LicenseCC Attribution-NonCommercial-ShareAlike License

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Behaviour-driven development and acceptance tests on Java web applications Presentation Transcript

  • 1. Behaviour-driven development... and acceptance tests on Java web applications Francisco Souza @franciscosouza franciscosouza.net giran.com.br
  • 2. Tests... Hey, developer!
  • 3. how did we work?
  • 4. http://www.flickr.com/photos/seandreilinger/2154168478/ Manual testing
  • 5. Annoying http://www.flickr.com/photos/pusspaw/745074637/
  • 6. http://www.flickr.com/photos/40045029@N07/4641262811/ Mecanic
  • 7. Don't you like it?
  • 8. Don't you like it? Do it better!
  • 9. http://www.flickr.com/photos/statusfrustration/143040265/ Selenium
  • 10. Automatization
  • 11. Selenium IDE
  • 12. Selenium RC
  • 13. TDD
  • 14. test
  • 15. test first?
  • 16. how did we work?
  • 17. As a user I want to see the pa ge title“Google” on www .google.com.br. Specification
  • 18. Tests?
  • 19. a test is a runnable specification
  • 20. You can leave your post-it and use case specification in a outdated box
  • 21. You can leave your post-it and use case specification in a outdated box but you have to update your tests!
  • 22. You can leave your post-it and use case specification in a outdated box Agreed! but you have to update your tests!
  • 23. show me the code!
  • 24. show me the code! package net.franciscosouza.selenium; import com.thoughtworks.selenium.*; public class TestGoogleHomePage extends SeleneseTestCase { public void setUp() throws Exception { setUp("http://www.google.com.br/", "*chrome"); } public void testGoogleTitle() throws Exception { selenium.open("http://www.google.com.br"); assertEquals("Google", selenium.getTitle()); } }
  • 25. Ugly! http://www.flickr.com/photos/zanini/4924308668/
  • 26. and the customer?
  • 27. As a user I want to see the pa ge title“Google” on www .google.com.br.
  • 28. Given
  • 29. Given that I am on the browser start page
  • 30. Given that I am on the browser start page When
  • 31. Given that I am on the browser start page When I go to the website www.google.com.br
  • 32. Given that I am on the browser start page When I go to the website www.google.com.br Then
  • 33. Given that I am on the browser start page When I go to the website www.google.com.br Then the title of page should be “Google”
  • 34. is it possible?
  • 35. JBehave http://www.flickr.com/photos/nocas/12555343/
  • 36. 01. Write the story
  • 37. 01. Write the story Given that I am on the browser start page When I go to the website www.google.com.br Then the title of page should be "Google"
  • 38. 02. Define the steps
  • 39. 02. Define the steps public class GoogleSteps extends SeleneseTestCase { @Given("that I am on the browser start page") public void openTheBrowser() throws Exception { this.setUp("http://www.google.com.br", "*chrome"); } @When("I go to the website www.google.com.br") public void goToGoogleHomePage() { this.selenium.open("/"); } @Then("the window title should be Google") public void testTitle() { assertEquals("Google", this.selenium.getTitle()); } }
  • 40. 03. Step runner
  • 41. 03. Step runner public class GoogleTitle extends JUnitStory { @Override public Configuration configuration() { return new MostUsefulConfiguration() .useStoryLoader(new LoadFromClasspath(this.getClass().getClassLoader())) .useStoryReporterBuilder(new StoryReporterBuilder().withDefaultFormats().withFormats(Format.CONSOLE, Format.TXT)); } @Override public List<CandidateSteps> candidateSteps() { return new InstanceStepsFactory(this.configuration(), new GoogleSteps()).createCandidateSteps(); } }
  • 42. 04. Run Forest run!
  • 43. 04. Run Forest run! Di dn 't =/ o w r k
  • 44. What is the problem with JBehave?
  • 45. What is the problem with JBehave? Dependencies
  • 46. What is the problem with JBehave? Dependencies i18n
  • 47. What is the problem with JBehave? Dependencies i18n I couldn't get this on my machine =/
  • 48. http://www.flickr.com/photos/mein_arkengel/3728122696/ Boring
  • 49. http://www.flickr.com/photos/torimercedes/2837826814/ Have fun?
  • 50. You can have fun with BDD :)
  • 51. You can have fun with BDD :) And you should!
  • 52. Gherkin Syntax
  • 53. Cucumber
  • 54. Lettuce
  • 55. Ruby?
  • 56. Ruby? Python?
  • 57. Ruby? Python? I am a Java developer!
  • 58. JRuby? Python? I am a Java developer!
  • 59. JRuby? Jython? I am a Java developer!
  • 60. is it possible?
  • 61. Cucumber
  • 62. 01. Install JRuby $ rvm install jruby $ rvm jruby
  • 63. 02. Install Cucumber and Selenium $ gem install cucumber $ gem install selenium-client
  • 64. 03. Write a feature Feature: Google homepage testing Scenario: Title of Google homepage Given that I am on the browser start page When I go to the website www.google.com.br Then the title of page should be "Google"
  • 65. Understand: A feature has many scenarios. A scenario has many steps.
  • 66. 04. Define the steps using Ruby and Selenium
  • 67. 05. Run the tests $ cucumber
  • 68. Couldn't I write step definitions in Java? http://www.flickr.com/photos/smull/356355686/
  • 69. You can! ;)
  • 70. Cuke4Duke http://www.flickr.com/photos/sharynmorrow/4860775922/
  • 71. You can use Maven, Ant or command line
  • 72. You can use Maven, Ant or command line I like command line :)
  • 73. 01. Install cuke4duke gem $ gem install cuke4duke
  • 74. 02. Add the JARs to your project cuke4duke.jar picocontainer.jar http://cukes.info/maven/cuke4duke/cuke4duke/
  • 75. Advertise: Maven is the best way to add and manage cuke4duke in your project ;) http://cukes.info/maven/
  • 76. 03. Write copy the feature Feature: Google homepage testing Scenario: Title of Google homepage Given that I am on the browser start page When I go to the website www.google.com.br Then the title of page should be "Google"
  • 77. 04. Define the steps using Java and Selenium public class GoogleHomePageSteps extends SeleneseTestCase { @Before() public void setUpSelenium() throws Exception { this.setUp("http://www.google.com.br", "*chrome"); } @Given("that I am on the browser start page") public void openBrowser() { this.selenium.open("/"); } @When("I go to the website www.google.com.br") public void goToGoogle() { this.selenium.open("http://www.google.com.br"); } ...
  • 78. 04. Define the steps using Java and Selenium @Then("the title of page should be "(.*)"") public void checkTitle(String title) { assertEquals(title, this.selenium.getTitle()); } @After public void closeSelenium() { this.selenium.close(); } }
  • 79. 05. Run Forest run! $ cuke4duke --jars lib --require bin/ features
  • 80. 05. Run Forest run! $ cuke4duke --jars lib --require bin/ features Folder containing your .class files Folder containing your Folder containing your .jar files .feature files
  • 81. i18n http://www.flickr.com/photos/78617484@N00/2656184369/
  • 82. Portuguese ;) # language: pt Funcionalidade: Teste da página inicial do Google Cenário: Título da página inicial do Google Dado que estou na página inicial do navegador Quando eu vou para a o site www.google.com.br Então o título da página deve ser "Google"
  • 83. Cucumber actually (2010 Sep 11) spoken 45 languages
  • 84. Stop the manual testing right now!
  • 85. Stop the manual testing right now! Enjoy Cucumber :)
  • 86. Francisco Souza @franciscosouza www.franciscosouza.net