开发者

Do I need a unit test constructor?

开发者 https://www.devze.com 2023-01-31 08:17 出处:网络
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 test

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

精彩评论

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

关注公众号