Slide 1

Slide 1 text

Spock & Geb: Clear and comprehensible tests! 27.06.2017 Ralf D. Müller, Tobias Kraft

Slide 2

Slide 2 text

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

Slide 3

Slide 3 text

3 Functional Testing with Geb Integration of the Business Department Comprehensible Reporting Spock – short and clear

Slide 4

Slide 4 text

4 JUnit vs. Spock

Slide 5

Slide 5 text

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

Slide 6

Slide 6 text

6 Clear Structure of Test-Code n-times

Slide 7

Slide 7 text

7 Data-Driven-Testing

Slide 8

Slide 8 text

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…

Slide 9

Slide 9 text

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)

Slide 10

Slide 10 text

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

Slide 11

Slide 11 text

11 Functional Testing with Geb Integration of the Business Department Comprehensible Reporting Spock – short and clear

Slide 12

Slide 12 text

12 Business specifies Tests

Slide 13

Slide 13 text

13 Business specifies Tests

Slide 14

Slide 14 text

14 Specification is turned into scaffolded Tests

Slide 15

Slide 15 text

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?!

Slide 16

Slide 16 text

16 Functional Testing with Geb Integration of the Business Department Comprehensible Reporting Spock – short and clear

Slide 17

Slide 17 text

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/

Slide 18

Slide 18 text

18 Spock with Geb = Dream-Team Geb Testing Adapter WebDriver Spock Geb

Slide 19

Slide 19 text

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()

Slide 20

Slide 20 text

20 Page Objects – to create modular tests

Slide 21

Slide 21 text

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?!

Slide 22

Slide 22 text

22 Functional Testing with Geb Integration of the Business Department Comprehensible Reporting Spock – short and clear

Slide 23

Slide 23 text

23 Problems of Test-Reports ● Tests just fail or succeed ● Power-Assertions are very supportive: ● 3 Report-Engines available for Spock

Slide 24

Slide 24 text

24 Standard Gradle Reports

Slide 25

Slide 25 text

25 Standard Gradle Reports

Slide 26

Slide 26 text

26 Spock 1.0-SNAPSHOT Report http://spockframework.github.io/spock/sampleReports/Ninja%20Commander.html

Slide 27

Slide 27 text

27 Spock-Reports Plugin by Renato Athaydes https://github.com/renatoathaydes/spock-reports

Slide 28

Slide 28 text

28 But what has been tested? ● Errors are hints that tests are not faked ● But otherwise, the reports just copy the specification

Slide 29

Slide 29 text

29 Solution – Geb Screenshots

Slide 30

Slide 30 text

30 Solution – Spock Reports with Geb Screenshots https://github.com/rdmueller/etka15

Slide 31

Slide 31 text

31 Solution – Spock Reports with Geb Screenshots

Slide 32

Slide 32 text

32 • Less manual testing • Comprehensible Tests Summary • Maintainable Tests with Spock and Geb • Business helps to create Tests • Better Quality

Slide 33

Slide 33 text

Any Questions? Thank you for your attention! @tokraft [email protected] @RalfDMueller [email protected]

Slide 34

Slide 34 text

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/