I have a method similar to this:
public List<MyClass> DoSomething(string Name, string Address, string Email, ref string ErrorMessage)
{
//Check for empty string parameters etc now go and get some data
List<MyClass> Data = GetData(Name, Address, Email);
/*************************************************************
//How do I unit test that the data variable might be empty???
*************************************************************/
List<MyClass> FormattedData = FormatData(Data);
return FormattedData;
}
I’m just learning TDD/Unit Testing. My question is, how do I write a test to ensure that if GetData returns an empty list I set ErrorMessage to something and then return a empty list?
When developing you should have left an “entrance point” for testing like this:
And in the Unit Testing you should
mocktheIDataProviderIt’s called Dependency Injection (DI) or Inversion Of Control (IOC)
common mocking library:
The list was taken from here
Wikipedia articles:
Dependency Injection
Inversion Of Control
NUnit pseudo code: