SlideShare ist ein Scribd-Unternehmen logo
1 von 42
Practicing Advanced 
Unit Testing 
v2.3.2 (17.09.2014) 
withthe 
«Trading Card Game» 
Kata 
Battlecry: Draw a slide. 
Deathrattle: Transform 
audience into 1/1 sheep. 
Speaker
Kata 
Kata (型or 形literally: "form”) is 
a Japanese word describing detailed 
choreographed patterns of movements 
practiced either solo or in pairs.
Trading Card Game (TCG) 
A […] trading card game (TCG) […] is 
a card game that uses specially 
designed sets of playing cards […] 
mass-produced for trading or 
collectibility, and it must have rules 
for strategic game play. Acquiring 
these cards may be done by trading 
with other players or buying card 
packs.
Why invent another Kata? 
Bro, why U not use 
????? 
Rules not 
extensible 
Not TDD-friendly 
Too easy
Hearthstone: Heroes ofWarcraft®
Kata Trading Card Game
Player Setup 
Health Mana 
30 0/0 
0 0 1 2 2 2 3 3 
3 4 4 4 5 6 6 7 8 
Deck 
1 3 
5 
Hand
Cause 
1 Damage 
30 0/0 30 
2 
7 
Active 
Player 
1 3 5 
8 
01//11 
Gameplay 
2 
3 
Play Card 1 
29 
0/0 
Draw Card 
-1 
Receive +1 
Replenish Mana Slot 
Mana 
Pay 1 
Mana 
Game 
Table 
Draw extra 
Card
Forced Turn Skip 
0/1 
30 1/1 
29 
5 8 2 
3 2 
2 4 
3 
No affordable 
Cards 
2/2 
7
2/-2 
29 
27 
4 
Ongoing Gameplay 
0/2 
30 1/1 
5 8 2 
3 2 
3 4 
2 
2 
7
12 
4 
Overload Rule 
8/8 
18 7/7 
5 8 7 
6 1 0 8 
2 
Discard Card 
when Hand 
already holds 
5 Cards 7
Mana Cap 
10/10 4 
5 
8 10/10 
6 Mana is 6 1 
capped at 
10 Slots
Bleedout Rule 
Cause 
1 Damage 
10/10 4 
5 
8 10/10 
Drawing 
from empty 
6 6 1 
Deck 
7-1
Game End 
10/10 4 
5 
4/10 
7 10/10 
--62 
6 6 1 
Winner! Loser!
Kata TCG Rules & Variations 
https://github.com/bkimminich/kata-tcg 
Detailed rules description 
Advanced Variations 
Healing cards 
Use cards as Minions 
Different cost & damage 
Card drawer cards 
Deck customization
Kata TCG Sample Solution in Java 
https://github.com/bkimminich/kata-tcg 
Java 8 
Lambdas & Stream API 
Junit 
Mockito 
For handling dependencies of tested objects 
Hamcrest 
Matchers for better legibility in assertions 
System Rules 
JUnit@Rules for substituting java.lang.System
Other Sample Solutions 
https://github.com/bkimminich/kata-tcg 
Groovy 
Spock 
JavaScript 
Karma 
Jasmine 
PhantomJS
Advanced Unit Testing 
Examples
Skip No-Brainers 
… 
Compile Error 
as Red Test 
Red 
Refactor Green
Obvious Implementation 
Simplest 
possible step 
Simplest 
useful step
Specify theObject under Test 
Irrelevant 
Details 
Setter introduced 
for testing 
Implementation 
Detail 
Assuming 
Hidden Default
Define theObject under Test 
Another unwanted 
setter 
Hidden default 
problem solved
Builder Pattern 
Reads like natural 
language 
Explicitly listed 
Expectations 
No unnecessary 
details 
…?
Builder Internals 
Sensible 
Default Values 
Package visible full 
Constructor needed
Fluent API 
Setting properties 
via fluent API
Mocking Behavior 
Interface has no 
implementation yet 
Mock Behavior 
for this Test
Trashcan Refactoring 
CardPicker turned out 
to be overengineered 
Mocking
Mocking BDD Style 
Can be 
confused with 
Given-When-Then 
part 
Can be 
confused with 
Given-When-Then 
part
Mocking BDD Style 
Sugar coating 
for BDD syntax 
Matches its meaning in 
Given-When-Then structure
Avoid Redundancy 
Redundant & spoiled with 
Implementation Details 
Another slight 
redundancy
Avoid Constants 
Disturbs the 
reading flow
Syntactic Sugar 
Improves 
Legibility and 
removes 
Redundancy
More Syntactic Sugar 
Magic 
Numbers Different Level of 
Abstraction
Syntactic Artificial Sweetener 
No-Op 
Syntactic 
Sugar for 
Legibility 
Syntactic 
Sugar reduces 
Redundancy
Test Diabetes 
Too much Sugar is 
bad for your Test 
Customer Matchers 
can medicate this
Custom Matcher 
Encapsulation of 
Expectation 
Produces helpful 
Error Messages 
Even better 
with just a little 
bit of Sugar
Demo | Q&A
Demo: Test Execution 
Pretty fast All tests pass
Demo: Code Coverage
UglUygRleytUroI UI 
Demo: Human vs. AI Game 
Player Input 
via System.in 
AI beats me! 
Again! 
Thank you for your attention! 
Recording of this talkat „Agile SaturdayX“ in Tallinn, Estonia 
https://vimeo.com/92886146 
https://twitter.com/bkimminich 
https://linkedin.com/in/bkimminich 
https://google.com/+BjörnKimminich 
http://slideshare.net/BjrnKimminich/
Credits 
Background Image: Demonplay (Permission of use granted) 
Other Images: 
Blizzard Entertainment (Permission of use requested) 
Wikipedia, Github, Agile Estonia 
Allmystery.de, Gueball.de, Natekohl.net, Scenicreflections.com 
Hearthstone: Heroes of Warcraft® is a trademark or registered trademark of 
Blizzard Entertainment, Inc., in the U.S. and/or other countries.

Weitere ähnliche Inhalte

Kürzlich hochgeladen

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Kürzlich hochgeladen (20)

The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 

Empfohlen

Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 

Empfohlen (20)

Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
 

Practicing Advanced Unit Testing

  • 1. Practicing Advanced Unit Testing v2.3.2 (17.09.2014) withthe «Trading Card Game» Kata Battlecry: Draw a slide. Deathrattle: Transform audience into 1/1 sheep. Speaker
  • 2. Kata Kata (型or 形literally: "form”) is a Japanese word describing detailed choreographed patterns of movements practiced either solo or in pairs.
  • 3. Trading Card Game (TCG) A […] trading card game (TCG) […] is a card game that uses specially designed sets of playing cards […] mass-produced for trading or collectibility, and it must have rules for strategic game play. Acquiring these cards may be done by trading with other players or buying card packs.
  • 4. Why invent another Kata? Bro, why U not use ????? Rules not extensible Not TDD-friendly Too easy
  • 7. Player Setup Health Mana 30 0/0 0 0 1 2 2 2 3 3 3 4 4 4 5 6 6 7 8 Deck 1 3 5 Hand
  • 8. Cause 1 Damage 30 0/0 30 2 7 Active Player 1 3 5 8 01//11 Gameplay 2 3 Play Card 1 29 0/0 Draw Card -1 Receive +1 Replenish Mana Slot Mana Pay 1 Mana Game Table Draw extra Card
  • 9. Forced Turn Skip 0/1 30 1/1 29 5 8 2 3 2 2 4 3 No affordable Cards 2/2 7
  • 10. 2/-2 29 27 4 Ongoing Gameplay 0/2 30 1/1 5 8 2 3 2 3 4 2 2 7
  • 11. 12 4 Overload Rule 8/8 18 7/7 5 8 7 6 1 0 8 2 Discard Card when Hand already holds 5 Cards 7
  • 12. Mana Cap 10/10 4 5 8 10/10 6 Mana is 6 1 capped at 10 Slots
  • 13. Bleedout Rule Cause 1 Damage 10/10 4 5 8 10/10 Drawing from empty 6 6 1 Deck 7-1
  • 14. Game End 10/10 4 5 4/10 7 10/10 --62 6 6 1 Winner! Loser!
  • 15. Kata TCG Rules & Variations https://github.com/bkimminich/kata-tcg Detailed rules description Advanced Variations Healing cards Use cards as Minions Different cost & damage Card drawer cards Deck customization
  • 16. Kata TCG Sample Solution in Java https://github.com/bkimminich/kata-tcg Java 8 Lambdas & Stream API Junit Mockito For handling dependencies of tested objects Hamcrest Matchers for better legibility in assertions System Rules JUnit@Rules for substituting java.lang.System
  • 17. Other Sample Solutions https://github.com/bkimminich/kata-tcg Groovy Spock JavaScript Karma Jasmine PhantomJS
  • 19. Skip No-Brainers … Compile Error as Red Test Red Refactor Green
  • 20. Obvious Implementation Simplest possible step Simplest useful step
  • 21. Specify theObject under Test Irrelevant Details Setter introduced for testing Implementation Detail Assuming Hidden Default
  • 22. Define theObject under Test Another unwanted setter Hidden default problem solved
  • 23. Builder Pattern Reads like natural language Explicitly listed Expectations No unnecessary details …?
  • 24. Builder Internals Sensible Default Values Package visible full Constructor needed
  • 25. Fluent API Setting properties via fluent API
  • 26. Mocking Behavior Interface has no implementation yet Mock Behavior for this Test
  • 27. Trashcan Refactoring CardPicker turned out to be overengineered Mocking
  • 28. Mocking BDD Style Can be confused with Given-When-Then part Can be confused with Given-When-Then part
  • 29. Mocking BDD Style Sugar coating for BDD syntax Matches its meaning in Given-When-Then structure
  • 30. Avoid Redundancy Redundant & spoiled with Implementation Details Another slight redundancy
  • 31. Avoid Constants Disturbs the reading flow
  • 32. Syntactic Sugar Improves Legibility and removes Redundancy
  • 33. More Syntactic Sugar Magic Numbers Different Level of Abstraction
  • 34. Syntactic Artificial Sweetener No-Op Syntactic Sugar for Legibility Syntactic Sugar reduces Redundancy
  • 35. Test Diabetes Too much Sugar is bad for your Test Customer Matchers can medicate this
  • 36. Custom Matcher Encapsulation of Expectation Produces helpful Error Messages Even better with just a little bit of Sugar
  • 38. Demo: Test Execution Pretty fast All tests pass
  • 40. UglUygRleytUroI UI Demo: Human vs. AI Game Player Input via System.in AI beats me! Again! 
  • 41. Thank you for your attention! Recording of this talkat „Agile SaturdayX“ in Tallinn, Estonia https://vimeo.com/92886146 https://twitter.com/bkimminich https://linkedin.com/in/bkimminich https://google.com/+BjörnKimminich http://slideshare.net/BjrnKimminich/
  • 42. Credits Background Image: Demonplay (Permission of use granted) Other Images: Blizzard Entertainment (Permission of use requested) Wikipedia, Github, Agile Estonia Allmystery.de, Gueball.de, Natekohl.net, Scenicreflections.com Hearthstone: Heroes of Warcraft® is a trademark or registered trademark of Blizzard Entertainment, Inc., in the U.S. and/or other countries.