0

我有一堂课:

 public class SourceServerProvider : ISourceServerProvider
    {
        private readonly ISourceServer _sourceServer;
        public SourceServerProvider()
            :this(new SourceServer())
        { }

        public SourceServerProvider(ISourceServer sourceServer)
        {
            _sourceServer = sourceServer;
        }
     }

对此块的 MS 代码覆盖率测试投诉:

public SourceServerProvider()
            :this(new SourceServer())
        { }

我不知道如何为上面的块编写单元测试。请指教..

4

1 回答 1

0

我刚刚使用以下代码对其进行了测试:

public class SourceServerProvider : ISourceServerProvider
{
private readonly ISourceServer _sourceServer;
public SourceServerProvider()
    : this(new SourceServer())
{ }

public SourceServerProvider(ISourceServer sourceServer)
{
    _sourceServer = sourceServer;
}
}

public interface ISourceServer
{
}

public class SourceServer : ISourceServer
{
}

public interface ISourceServerProvider
{
}

并写了这个测试

public class Class1
{
    [Test]
    public void test()
    {
        var a = new SourceServerProvider();
    }
}

代码覆盖率表示它已完全覆盖: 这里

所以请添加你得到的结果或创建调用默认ctor的简单测试

于 2014-01-31T18:19:31.107 回答