Hello everyone.
For last 1+ year, i have been doing a pet project to practice TDD and try to implement some design principles.
In essence, I 100% followed two main principles of TDD and coding. Those are:
1. Never repeat your code.
2. Never write development code without test code.
After 1+ year, this project has evolved in 20+ Entities and respective Gateways, Managers and Unit test classes as well. You will get the test project's class diagram attached with this mail.
In summary, in my test project, i made an interface:
interface IManagerTest<T> where T:class
{
void Insert_Should_Return_IsSuccess_False_When_Object_Is_Null();
void Insert_Should_Return_IsSuccess_True_When_Object_Is_Saved();
void Delete_Should_Return_IsSuccess_False_When_Object_Id_Not_Found();
void Delete_Should_Return_IsSuccess_True_When_Object_Is_Deleted();
void Update_Should_Return_IsSuccess_False_When_Object_Id_Not_Found();
void Update_Should_Return_IsSuccess_True_When_Object_Is_Updated();
void GetObjectById_Should_Return_Null_If_Id_Is_Null_Or_Empty();
void GetObjectById_Should_Return_Null_If_Object_Is_Not_Found();
void GetObjectById_Should_Return_Object_If_Id_Is_Found();
void GetAll_Should_Return_List_Of_Objects();
DSResult Insert(T o);
DSResult Delete(T o);
void AssertProperties(T expected, T actual);
}
I added extra method in test class if needed.
And each of my Manager Tester classes implements that interface. For example:
[TestClass]
public class AdviceManagerTest : TestBaseManager, IManagerTest<t_Advice>
{
.........
.........
}
And for example, the implementation of AssertProperties method is like below:
public void AssertProperties(t_Advice expected, t_Advice actual)
{
........
.......
}
My question is:
- Did i break any rule of TDD by using interface in unit testing?
- What alternatives do I have if i don't want to use the mentioned interface for testing the managers?
- I will be really helped if someone please made some critics on the code and the design also.
I am ready to share some of the .CS files if anyone interested to see.
Sincerely
Foyzul Karim
The Databiz Software Limited
Dhaka
Bangladesh