Are There Any Programming Katas Related to Testing?
Can we use code katas for testing?
Join the DZone community and get the full member experience.
Join For FreeWhat would be suitable code katas for people wanting to learn how to code to support their testing?
Code katas are a pretty popular concept for programming:
- https://www.codewars.com/
- http://www.codingdojo.org/
- https://en.wikipedia.org/wiki/Kata_(programming)
- https://leanpub.com/codingdojohandbook
I don’t do code katas. John Somnez also writes about why he doesn’t do code katas here, and here is another take on code katas from Micah Martin
Why I Don’t Do Code Katas
- Time
- I don’t really have time to dedicate to code katas
- Usefulness
- When I’m learning a language, I really want the code to be useful because that is what motivates me to learn more.
- I don’t want to keep doing the same thing
But I realized recently that I might do code katas, but I haven’t called them that.
My Code Katas
I have written CounterString
implementations in:
- VBA (Excel) code
- VB (code lost)
- Java main code, Java
- JavaScript predictive, reverse
I have approached the writing of CounterString
differently each time I created a new implementation.
And I have revisited my implementation as I learned more about the programming language.
Exercise
If you want to use CounterStrings
as a way to practice your programming, and potentially consider it a code kata, here are my suggestions:
- Write code to generate a String starting with
*
, and then3*
, etc. to the length of yourCounterString
, e.g this would create a ten characterCounterString
like*3*5*7*9*1
. I describe this as Forward CounterString Generation - Write code to generate a
CounterString
that matches how JamesBach describes it where the string ends with*
and is of the required length and the number before each*
is the position of the*
in the string, so a 10-characterCounterString
would read*3*5*7*10*
- Instead of writing out your
CounterString
to the console, write it to a file - Instead of writing out your
CounterString
to the console, write it to the clipboard - Instead of writing out your
CounterString
to the clipboard, make it type it into a field - Find a different implementation approach, e.g. if you used recursion change it to do something else, if you didn’t use recursion try that, or if you were reversing strings, try doing it without reversing strings
- Create automated scripts that execute your implementation and compare the output with a different implementation, e.g. James Bach’s perl clip. This might initially be a pre-generated file or responses, but create one that calls
PerlClip
dynamically - For the ‘ultimate’ challenge, try writing an implementation that generates
CounterStrings
the way James Bach describes it, but do it dynamically so that you can stream the generation. I describe this as Predictive Forward CounterString Generation
With each of these, you will create something useful that supports you in your work. And you’ll learn something.
Other Suggestions
Other code that I seem to keep writing:
- Create a verb/noun text adventure game
- Write a link checker
- Write a calculator that takes a string, e.g. “2+4+7” and returns the result
- Write a test data generator using generative grammar
All of these can vary in complexity but provide useful learning tools. You’ll find examples of all of the above in my GitHub repos (but you might have to search a bit).
This article was syndicated from blog.eviltester.com. Author Alan Richardson is an Agile Software Development and Testing Consultant he has written 4+ books including Dear Evil Tester, Automating and Testing a REST API, Java For Testers. He has created 6+ online training courses covering Technical Web Testing, Selenium WebDriver and other topics. He is a prolific content creator on his blog, Youtube and Patreon.
Published at DZone with permission of Alan Richardson, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Trending
-
RBAC With API Gateway and Open Policy Agent (OPA)
-
Extending Java APIs: Add Missing Features Without the Hassle
-
Observability Architecture: Financial Payments Introduction
-
Effective Java Collection Framework: Best Practices and Tips
Comments