Although the idea of doing code kata to practice TDD is quite popular, I couldn't get on this train for a long time. The reason was that I was striving to find a kata that would help me practice or demonstrate a mock-based TDD, at the same time being simple and showing all the testing categories, as well as test reflexology in practice.
This was until I ran into a situation that, with few simplifications, could be turned into a compelling kata to show off the power of mocks and Need-Driven Development.
I've decided to present the kata in a series of posts. This one is going to be about the challenge only.
The challenge
Imagine the following situations: you're creating a message processing module for a system that receives data in a form of frames from the network. The frame parsing is done using a proprietary third party library and your module receives the frames as deserialized objects. As the class for the objects is stored in the third-party library, you cannot change it (e.g. add or remove methods or change any signature).
There is only one type of frame, described below:
public class Frame { int Speed { get; set; } int Age { get; set; } string Sender { get; set; } }
Your task is to implement the message processing. So far, it only consists of validation and nothing more. Each field of each incoming frame is validated. The following examples describe the validation rules:
type of field | Correctness criteria | When satisfied | When not satisfied |
---|---|---|---|
int | greater than 0 | do nothing | throw exception |
string | not null and not empty | do nothing | throw exception |
Of course, you have to do this test-first.
Two more posts to come - one for failure, one for success
I believe that failure and success are both great opportunities to learn something valuable. So in the next post, I'll try to show you how to screw up :-) and what we can learn from the failure by listening to the tests.
In the meantime, you can try to solve the kata yourself (coming up with any solutions should be trivial) and share your observations.
Good night, everyone!
No comments:
Post a Comment