【发布时间】:2020-11-09 12:00:47
【问题描述】:
我在 Nunit 中使用 Moq 进行了以下测试:
[TestFixture]
public class MessageServiceTests
{
private Mock<IFtpClient> _ftpService;
private IMessageService _messageService;
[SetUp]
public void Setup()
{
_ftpService = new Mock<IFtpClient>();
_messageService = new MessageService(_ftpService.Object);
}
[Test]
public void SendAsync_WithSettings_ConnectsWithCredentials()
{
//act
_messageService.SendAsync(It.IsAny<Stream>(), It.IsAny<String>(), It.IsAny<Settings>());
}
}
以及以下被测试的方法:
public async Task SendAsync(Stream stream, string fileName, Settings settings)
{
throw new NotImplementedException();
}
预计测试会失败,但是当我在 Visual Studio 中运行它时它会通过。我无法理解它,当抛出意外异常时测试应该失败,对吧?那为什么会通过呢?
【问题讨论】:
标签: c# unit-testing nunit moq