namespace spec_for_message_processor
{
[TestFixture]
public class when_the_message_processor_processes_a_valid_message {
[Setup]
public void context() {
}
[Test]
public void should_call_the_packager_to_package_artifacts() {
}
}
}
Let's look at this structure and pick it apart a little.
- The namespace reflects the spec for what we are testing. This could be a class or a module where we need to test the interactions and the behavior of that class or module.
- The name of the class uses then when x happens wording. This wording places context around what you are testing.
- The name of the method states what should happen based on the context, so in this example when the message processor processes a valid message then it should call a packager to package some artifacts.
This approach reads well from top to bottom and it makes it easier in my opinion to understand what the intent and purpose of the code is. In my next blog post I will discuss using inheritance in my tests and how that changes what we have written here.
No comments:
Post a Comment