I've got a simple CRUD based application to be done. I'm trying to approach this in a TDD way. I'm a newbie to TDD and cannot actually understand how to proceed with my tests.
The scenario is:
You can assume this to be a commandline application for simplicity. (I'm actually going to do this as a WPF MVVM application.)
I'm not sure what my first test should be.
What I have tried so far is:
Assumed that I have a Employee repository that returns a set of Employees.
My attempted first test was:
[Test]
public void RepositoryShouldReturnTheListOfEmployees()
{
var repository = new EmployeeRepository();
var employees = repository.GetEmployees();
Assert.IsNotEmpty(employees);
}
I started with this and then return an Employee object from the GetEmployees() method to make my test pass. Then once the test was passing I refactred the EmployeeRepository to implement an interface and used that on the test method.
This is a quite trivial task and this approach appears to be an overkill for me (at least for now). But I'm sure that when the application grows bigger testing any even the trivial things would start to pay off.
But I have a feeling that something is not right in my approach. Would an experienced TDDer would follow the same approach? or what would that be. Also I can't think of a test that I could use for "Add Employee" functionality.
I can skip these CRUD scenarios and may be try to test drive other more complicated functionalities.. but is that a correct approach?
Basically what I'm doing right now is test driving my repository which doesn't do anything much other than persisiting and retrieving information. So far this TDDing this appeared to be a quite mundane task to me.
Appreciate all your inputs.
Sometimes doing the right thing is boring.
Here's how I look at this..
Your EmployeeRepository is a role, which is supposed to support CRUD for EmployeeObjects. So this is a port between your application and the DB/datastore. (Refer to Ports and Adapters pattern Cockburn et all).