我有一个班级:
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())
{ }
我不知道如何为上面的块编写单元测试。请指教..
答案 0 :(得分: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的简单测试