TDD (Test Driven Development). What is it? According to Extreme Programming, TDD is an incremental software development approach that relies on automated regression tests to steer development activities .
By using TDD, the steps for developin software are Test – Coding – Design. This is the simple life cycle for develop a system using TDD.
Life Cycle – Test Driven Developmet
Let me explain the life cycle for you:
If you just read the theory without an example, it just like a folktale. Right? Now I will give an example to use the TDD approach.
Assume that we want to make a service to add and multiply. Let start from provide some test lists. So what are the test lists. Add and multiply, these are the test lists.
using NUnit.Framework;
public class MyServiceFixture
{
Assert.AreEqual(4, myService.Add(2, 2));
}
This is test case for add. You want to ensure that the result of 2 + 2 is 4. You can use method AreEqual to check the result. Compile your code. Some erros will occur, because the object myService is not identified. So make instatiate of an object myService.
using NUnit.Framework;
public class MyServiceFixture
{
IMyService myService = new MyService();
Assert.AreEqual(4, myService.Add(2, 2));
}
Compile again your code. Some errors have been reduced. Wow interface IMyService and class MyService are not found. Create the interface and class.
public interface IMyService
{
int Add();
}
public class MyService : IMyService
{
public MyService() {}
public int Add(_firstNumber, _secondNumber)
{
return _firstNumber + _secondNumber;
}
}
Now lets compile again your class MyServiceFixture. What is the result. No errors will be occured. You can try for the multiply test case.
Very interesting site, but you must improve your template graphics.