-
Notifications
You must be signed in to change notification settings - Fork 1
Unit Test Organisation
Thomas Klepzig edited this page Sep 16, 2016
·
11 revisions
- Every class of implementation which should be tested has one corresponding test class
- This class contains multipe test methods, every method is acting and asserting for its use case
- aka Testcase class per class
public class CalculatorTests
{
void Divide_should_return_2_for_10_and_5()
{
//arrange
//act
//assert
}
void Divide_should_throw_exception_by_dividing_by_zero()
{
//arrange
//act
//assert
}
}
- There is no exact mapping of an implementation-class to a test-class
- Instead, the tests are organized and named like requirements
- One test class is testing only one single method of one
- aka Testcase class per fixture
public class When_dividing_10_by_5
{
void arrange()
{
}
void act()
{
}
void It_results_to_2()
{
}
}
public class When_dividing_10_by_0
{
void arrange()
{
}
void act()
{
}
void It_throws_an_exception()
{
}
}
- Name the test-class like a requirement, as mentioned in 2.
- Make multiple acts and assertions (and so mutiple test methods) for different input parameters for the one method you want to test
http://xunitpatterns.com/Testcase%20Class%20per%20Fixture.html