Schlagwort-Archive: TestNG

Gilded Rose Test Kata–Summery

Finally I managed to finish my project during my vacation. I created three different kinds of solution to get 100 % test coverage for the Gilded Rose Kata. The first attempt was made with TestNG because I like this framework very much. My second choice was JUnit.

What I found very interesting was that I needed less code to get 100 % coverage with JUnit than with TestNG. My assumption is that I included more variations with TestNG because it is so much easier to add a new variant to an existing case. Another reason could be that I know the corner cases of the Kata much better and I could focus on these specialties.

The third attempt was made with JBehave. First I tried to have a “normal” Eclipse project. I wanted to store the necessary libraries in a folder inside the project. This attempt was not successful. I could not figure out which libraries are needed and at the end after some trial and error I dismissed this effort. Instead I switched to Maven. There are some examples shipped with JBehave and with the help of the “Game of life” sample I managed to create a solution using JBehave.

So far the JBehave solution took the least amount of code and writing. It is also really easy to add a new test scenario with little effort. But there are also some drawbacks:

  • For the first attempt it was quite difficult to get the stories connected to the annotations.
    Little hint: The key words Given, When and Then from the stories are transformed to the corresponding annotations so they should not be part of the annotation attribute.
    Wrong: @Given(“Given is something”)
    Correct: @Given(“is something”)
  • If a parameter from the story is a string then the string is created using new String. I found out about this behavior because the Kata is using == to compare two strings instead of .equals(). As a result the if-statements switched to different branches than I expected. To avoid this behavior in my solution I had to translate the parameter into a “normal” string so the comparison of two strings works as expected.
  • For every story in the test you have to create a corresponding Java class otherwise JBehave is complaining. But if you run every test class in one package all tests are running as many times as test classes.

JBehave is a layer on top of “any” test framework. In my solution I took JUnit as the underlying test framework but TestNG and other frameworks are also possible.

The complete code for the Kata and the three solutions can be found on Github.