Do I need a unit test constructor?
I have projects set up as follows:
- Data - repository.
- Service
- Web
I'm using NUnit, and I'm testing a method that is in Service
Project. When I first used MSTest to automatically setup these tests for me, it created a unit test constructor that looks like this:
Service service;
[Test]
public void ServiceConstructorTest()
{
IRepository repository = null; // TODO: Initialize to an appropriate value
service = new Service(repository );
Assert.Inconclusive("TODO: Impl开发者_Go百科ement code to verify target");
}
When I try to test a method, this constructor is not executed and service
ends up being null. Am I going to have to declare and mock every time I write a test?
NUnit has a [SetUp] attribute that you put on a method, and that method will be called before each test is executed. There is also a [TearDown] attribute that causes the method to be run after each unit test as well.
精彩评论