Category Archives: Test Driven Development

Diamond Kata in Java

Someone recently has sent me Nat Pryce’s blog post with his property test driven approach to diamond kata. I had a quick look and decided to try diamond kata myself.

Read the rest of this entry

Bad Practices of Testing presentation

Recently I gave a presentation called “Bad Practices of Testing”. It shows the most common mistakes done while writing tests, describes problems they cause and shows how to do it better. Slides are done using github markdown so you can read it online here:

Random number generator using modulo

You have probably heard about modulo bias using random number generator. If you read Effective Java by Joshua Bloch this problem is described in Item 47. But did you ever think why there is a problem with simple code like this Math.abs(rnd.nextInt()) % n ? Why the distribution of elements is not equal and by how much is it exactly biased? Here is the mathematical explanation:

Read the rest of this entry

What to mock and why not to mock data objects?

Recently when reviewing my code before opening a pull request, I have noticed a few methods that I felt were untested. I have run all tests with coverage and indeed 7 methods in the class were not covered. The class was a data object and all these 7 methods were mostly getters and setters so the following questions arose:

  • Should I have a unit test for data object?
  • Should I be testing getters and setters?
  • Why I never had to do this before?

Read the rest of this entry

TDD learning materials

Recently I have been giving internal presentation in Gamesys about how to do Test Driven Development. A simple exercise is available in my github repository. Extra thanks to Mani Sarkar for his input in preparing this exercise.

Read the rest of this entry