开发者

Do I need a unit test constructor?

I have projects set up as follows:

  1. Data - repository.
  2. Service
  3. 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜