Enter the Unit Test

Unit tests are small, method-level tests developers write every time they make a change to the software to prove the changes they made work as expected.

For example, say we wanted to verify our deck of cards had fifty-two cards in it (and not fifty-three). We could write a unit test that would look something like this:

tdd/test/DeckTest.cs
 
[TestFixture]
 
public class DeckTest
 
{
 
[Test]
 
public ​void​ Verify_deck_contains_52_cards()
 
{
 
var deck = new Deck();
 
Assert.AreEqual(52, deck.Count());
 
}

Just to be clear, the previous code isn’t the actual code we run as part of our Black Jack simulator in production. This is test code that verifies our real code works as expected.

Whenever we have a doubt about how ...

Get The Agile Samurai now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.