I'm trying to follow good practices when writing my testing suites. Halfway through i realised that iam spending alot (Most) of my time on the Fake Objects...Most of my tests does something like this
public interface ITemplateRepository
{
string get GetGenericTemplate {get;}
}
public FakeTemplateRepository : ITemplateRepository
{
public string GetGenericTemplate ()
{
return "<xml>Complex</xml>";
}
}
[Test]
public void CanGetGenericTemplate()
{
ITemplateRepository rep = new FakeTemplateRepository();
Assert.IsNotNull(rep.GetGenericTemplate());
}
[Test]
public void GetGenericTemplateContains()
{
ITemplateRepository rep = new FakeTemplateRepository();
Assert.IsTrue(rep.GetGenericTemplate().StartsWith("<xml>"));
}
I actually found myself spending alot of time on the FakeTemplateRepository, making sure it returned the actual content i was expecting. Is this a bad thing?
Is this still a valid Unit Test? Unit testing should be fast and simple, no? But honestly i'm not really sure, one thing for sure is that it got my thinking about the shape and content of my data. The content in the FakeRepository will more or less reflect my production content, albeit reading from the file system, instead of in-memory.
If in fact what i'm doing are Integration Tests, then how can should i use mocks for my unit tests?
It doesnt make sense to me (if using Mocks) that i set the expectation up so that it calls the method and returns a string? Am i missing something but i don't see much value there? The code wont even compile if i set an invalid method name!
I am really really confused about the whole thing and my perception of unit testing is totally blurred now with all these concepts.
Can any demonstrate with a super super simple example of how fakes and mocks fit into a suite? e.g What should be a unit test, What should be an integration test?
Thanks