Your SlideShare is downloading. ×
2014 GeeCON Custom Assertions
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Introducing the official SlideShare app

Stunning, full-screen experience for iPhone and Android

Text the download link to your phone

Standard text messaging rates apply

2014 GeeCON Custom Assertions

574
views

Published on

my GeeCON 2014 "lightning talk" about custom assertions

my GeeCON 2014 "lightning talk" about custom assertions

Published in: Software, Technology

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
574
On Slideshare
0
From Embeds
0
Number of Embeds
5
Actions
Shares
0
Downloads
9
Comments
0
Likes
1
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Custom Assertions ...when assertEquals() is not enough Tomek Kaczanowski
  • 2. freegreatpicture.com A 15 minutes „lightning talk”
  • 3. ● Developer ● Blogger ● Books author twitter: @tkaczanowski http://practicalunittesting.com Tomek Kaczanowski
  • 4. Expectations our tests should: ● verify americanmethod.com
  • 5. Expectations our tests should: ● verify ● be readable code.tutsplus.com
  • 6. Expectations our tests should: ● verify ● tell a story jasonfurnell.wordpress.com
  • 7. Expectations our tests should: ● verify ● tell a story ● be focused noble.org
  • 8. Expectations our assertions should: ● verify ● tell a story ● be focused
  • 9. The Evolution of Assertions
  • 10. The Evolution of Assertions
  • 11. The Evolution of Assertions
  • 12. The Evolution of Assertions
  • 13. The Evolution of Assertions
  • 14. Talk is cheap. Show me the code.
  • 15. assertThat(...)
  • 16. assertThat(...)
  • 17. assertThat(...)
  • 18. The Anatomy of Custom Assertion
  • 19. The Anatomy of Custom Assertion
  • 20. The Anatomy of Custom Assertion
  • 21. Custom Assertions or Private Methods? verifySuccessfulRedirect(response, FALLBACK_URL); dashboardShows(dashboardPage, „my campaign”, „Target”, „PL”); noHits(„2007-06-06 02:00”); noHits(„2007-06-06 03:00”); hitsAndRevenue(„2007-06-06 04:00”, 2, 7); ...
  • 22. Real Life Examples
  • 23. Real Life Examples actual
  • 24. Real Life Examples actual assertThat(found) .overwritingErrorMessage( „expected row for {} but found only rows for {}” stringDate, dates(actual) ) .isTrue();
  • 25. Real Life Examples actual
  • 26. Conclusions
  • 27. Upsides ● readable ● reusable ● simple to write ● cheap to maintain
  • 28. Upsides and Downsides ● need to write them ● can hide bad smells ● readable ● reusable ● simple to write ● cheap to maintain
  • 29. Best Practices use AssertJ • forget about JUnit/TestNG assertions introduce custom assertions • when private methods are not good enough • if you care about ubiquitous language • when “then” part is getting huge • to impress/confuse your team mates
  • 30. The Evolution of Assertions
  • 31. The Evolution of Assertions
  • 32. Links AssertJ: http://joel-costigliola.github.io/assertj/ tools used to prepare these slides • http://shaky.github.bushong.net/ • http://hilite.me/ • http://asciiflow.com
  • 33. Thank you! You can learn more about writing high quality tests by reading my books: „Practical Unit Testing” and „Bad Tests, Good Tests”. Please visit http://practicalunittesting.com to learn more.