Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Spock & Geb: Clear and comprehensible tests!

Spock & Geb: Clear and comprehensible tests!

Spock, Geb, BDD,
Tobias Kraft, Ralf D. Müller

Ralf D. Müller

June 27, 2017
Tweet

More Decks by Ralf D. Müller

Other Decks in Technology

Transcript

  1. 2 My source code is covered by automated tests ☺

    No Errors, but what has been tested? I have to test manually! Our system contains an expensive bug! Why hasn‘t it been found before? No Errors
  2. 3 Functional Testing with Geb Integration of the Business Department

    Comprehensible Reporting Spock – short and clear
  3. 5 Spock - Overview • BDD-Framework for Tests and Specs

    • Groovy as basis • DSL (Domain Specific Language) • General Testing for JVM-Languages • IDE-Support (Junit) • Version 1.1 since May 2017
  4. 8 Extensions via Annotations @Ignore("Not yet implemented") @IgnoreRest @IgnoreIf({ properties."os.name"

    ==~ /Linux.*/) }) @Timeout @FailsWidth @Requires({ env.containsKey(„DMS_ENABLED") }) @RestoreSystemProperties @Issue("http://jira.exensio.de/browse/GM-19") @See("http://ldaley.com/post/6570075743/") @Title("a readable title") @Narrative("a beautiful description for a report") Documentation Ignore and even more…
  5. 9 What else makes Spock special? • Interaction Based Testing

    • Stubs, Mocks und Spies • Exceptions • old method • Hamcrest Matchers when: myList.add('foo') then: myList.size() == old(myList.size()) + 1 then: def e = thrown(IllegalArgumentException) e.getMessage().startsWith("No tagCategory") expect: 2.9d closeTo(3, 0.5)
  6. 10 the automated tests are now readable by the business

    people… No Errors? But what has been tested? Can‘t I just specify what to test?! No Errors
  7. 11 Functional Testing with Geb Integration of the Business Department

    Comprehensible Reporting Spock – short and clear
  8. 15 Screenshot? Click a Link? Fill out Forms? No Errors

    No Errors? But what has been tested? Can‘t I just specify what to test?!
  9. 16 Functional Testing with Geb Integration of the Business Department

    Comprehensible Reporting Spock – short and clear
  10. 17 Geb - Overview • Webtesting and Screen-Scraping • DSL

    based on Groovy • jQuery like CSS Selectors • Uses same WebDriver as Selenium • IDE-Support • Integration with Spock, TestNG or Junit (or even Cucumber and JBehave?) • Version 1.1.1 • http://gebish.org/
  11. 19 HTML DOM-Selection with a JQuery-like Syntax Examples $("div", 2)

    $("td.odd", 0..2)*.text() $("img", alt: "Titel") $("img", alt: "Titel").previous() $("div#heading").find("div", 3) $("div", text: iStartsWith ("groovy")) $("form").find("input", name: "speaker").value()
  12. 21 I turned the business specs into automated Tests! (yeah!)

    Still just No Errors No Errors? But what has been tested? Can‘t I just specify what to test?!
  13. 22 Functional Testing with Geb Integration of the Business Department

    Comprehensible Reporting Spock – short and clear
  14. 23 Problems of Test-Reports • Tests just fail or succeed

    • Power-Assertions are very supportive: • 3 Report-Engines available for Spock
  15. 28 But what has been tested? • Errors are hints

    that tests are not faked • But otherwise, the reports just copy the specification
  16. 32 • Less manual testing • Comprehensible Tests Summary •

    Maintainable Tests with Spock and Geb • Business helps to create Tests • Better Quality
  17. 34 References • Spock und Geb: Übersichtlich und nachvollziehbar Testen

    für alle! Vortrag, Beispiele Source Code http://rdmueller.github.io/etka15/ • Teil 1 : Mit Mr. Spock beim Testeinsatz, Javamagazin (12/2014) Teil 2 : Mr. Spock ruft Geb, Javamagazin (01/2015) http://www.exensio.de/articles/