I have been thinking a lot about unit testing and how to improve the readability of the unit tests. I thought why not give a character to the classes in the unit test to clarify what they do.
Here is a simple unit test that I wrote:
[TestFixture]
public class when_dave_transfers_money_from_wamu_account_to_the_woodforest_account
{
[Test]
public void should_increase_the_amount_in_woodforest_account_when_transaction_successfull()
{
Dave dave = new Dave();
Wamu wamu = new Wamu();
wamu.Balance = 150;
wamu.AddUser(dave);
Woodforest woodforest = new Woodforest();
woodforest.AddUser(dave);
FundTransferService.Transfer(100, wamu, woodforest);
Assert.AreEqual(wamu.Balance, 50);
Assert.AreEqual(woodforest.Balance, 100);
}
}
Here is the Dave class:
/// <summary>
/// This is Dave!
/// </summary>
public class Dave : User
{
public Dave()
{
FirstName = "Dave";
LastName = "Allen";
}
}
The unit test name clearly serves the purpose. But, maybe I want to dig a little deeper and assign the Wamu and Woodforest accounts to Dave whenever Dave is created. The problem is that it will move away from readability as I will have to use index values to refer to the account.
What are your thoughts on making this more readable?