Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 模拟测试_C#_Unit Testing_Rhino Mocks - Fatal编程技术网

C# 模拟测试

C# 模拟测试,c#,unit-testing,rhino-mocks,C#,Unit Testing,Rhino Mocks,我有一个登录到数据库并检查用户名和密码的单元测试,但我现在需要使用mock重新创建这些测试 我一直在网上搜索,但找不到任何像我试图实现的东西。以下是原始测试 [TestMethod()] public void LoginTest() { this.errorText = string.Empty; this.user = MasterDataManager.GetInstance().Login("JohnSmith", "123", out errorText); A

我有一个登录到数据库并检查用户名和密码的单元测试,但我现在需要使用mock重新创建这些测试

我一直在网上搜索,但找不到任何像我试图实现的东西。以下是原始测试

[TestMethod()]
public void LoginTest()
{
    this.errorText = string.Empty;
    this.user = MasterDataManager.GetInstance().Login("JohnSmith", "123", out errorText);
    Assert.AreEqual(string.Empty, errorText);
}
我已经根据我在网上找到的东西写了一个测试,它通过了,但我真的不知道为什么要说实话。我在这里用过Rhino Mock,但我愿意接受任何帮助或解决方案来帮助我

[TestMethod()]
public void LoginTestMock()
{
    var repo = MockRepository.GenerateMock<IAbstractConnector>();
    repo.Login("JohnSmith", "123", out errorText);
    repo.VerifyAllExpectations();
}
[TestMethod()]
public void LoginTestMock()
{
var repo=MockRepository.GenerateMock();
回购登录(“JohnSmith”,“123”,out errorText);
回购协议验证所有预期();
}
回答你的“……它通过了,但我真的不知道为什么要说实话。”:它通过了,因为你没有设定任何期望,因此没有什么需要验证的。 支票


您认为“验证所有预期”将检查什么?你认为“通过单元测试”在这个上下文中实际上意味着什么?你想测试什么?我试图模拟一个返回空字符串的测试。你的测试只使用一个模拟,这没有多大意义。在我看来,您仍然应该调用与最初相同的方法,但是将一个模拟传递到被测试的类中,这样它就不会真正访问数据库。