Being new to test-based development, this question listened to me. How much is? What needs to be tested, how should it be tested, and why should it be tested? Examples are given in C # with NUnit, but I assume that the question itself is an agnostic of the language.
Here are two current examples of my own tests on a common list object (tested with strings, the initialization function adds three elements {"Foo", "Bar", "Baz"} ):
[Test] public void CountChanging() { Assert.That(_list.Count, Is.EqualTo(3)); _list.Add("Qux"); Assert.That(_list.Count, Is.EqualTo(4)); _list[7] = "Quuuux"; Assert.That(_list.Count, Is.EqualTo(8)); _list.Remove("Quuuux"); Assert.That(_list.Count, Is.EqualTo(7)); } [Test] public void ContainsItem() { Assert.That(_list.Contains("Qux"), Is.EqualTo(false)); _list.Add("Qux"); Assert.That(_list.Contains("Qux"), Is.EqualTo(true)); _list.Remove("Qux"); Assert.That(_list.Contains("Qux"), Is.EqualTo(false)); }
The code is pretty self-commenting, so I won’t go into what is happening, but is it too far? Add() and Remove() are tested separately, so what level should I use with these types of tests? Should I even carry out such tests?
language-agnostic tdd
Matthew scharley
source share