Doing Code Katas alone or in a Dojo can help sharpen our elementary skills as software developers. Practicing IDE shortcuts and TDD mini-step cycles is very useful for the daily business, yet I find some existing Code Katas too far away from real-life programming situations.
That’s why I came up with the Trading Card Game Kata – which is (very loosely) based on Blizzard Entertainment’s free-to-play online-game “Hearthstone – Heroes of Warcraft”. This Kata is focused on practicing TDD in a slightly more complex (but not complicated) situation where you might have to think about rules like Single Responsibility Principle or Command Query Separation and might even feel the urge to use a Mocking framework at some point. The rules are kept very simple to begin with but can be extended easily to make the Kata more challenging or concentrate on specific aspects of software development.
In this talk I will first introduce the ideas of Katas in general and explain the TCG Kata rules to you. Then I will present some real-life best practices for writing good developer tests, using my TCG Kata sample solutions as a showcase. This will include:
* Picking the right Test Double
* Test Data Builders
* Behavior Tests with BDDMockito
* Prose-like Assertions with Hamcrest
* Readability Sugar
* Custom Matchers against Test Diabetes
The full Kata ruleset and sample solutions in Java 8 (JUnit4, Mockito, Hamcrest) and Groovy (Spock) can be found on https://github.com/bkimminich/kata-tcg.
A recording of this talk at „Agile Saturday X“ in Tallinn, Estonia can be found on https://vimeo.com/92886146.
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
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
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.