简体   繁体   English

看起来 nSubsitute 只是在测试自己而不是我的代码

[英]It looks like nSubsitute is just testing itself rather than my code

Possibly stupid question.可能是愚蠢的问题。 In the docs they give this example在文档中他们给出了这个例子

calculator.Add(1, 2).Returns(3);
Assert.That(calculator.Add(1, 2), Is.EqualTo(3));

Am I testing that the actual calculator returns 3 or just that the substitute does?我是在测试实际计算器返回 3 还是只是替代计算器返回 3? If the latter, what is the point?如果是后者,那意义何在?

I think that in the example on the front page ( https://nsubstitute.github.io/ ), they are just showing that it works, it is not part of your test really.我认为在首页 ( https://nsubstitute.github.io/ ) 的例子中,他们只是表明它有效,它并不是你测试的一部分。

I'm not sure where my brain went, but I seem to have momentarily lost the point of a mock.我不确定我的大脑去了哪里,但我似乎暂时失去了模拟的意义。 Saying

calculator.Add(1, 2).Returns(3)

is the wrong example.是错误的例子。 A much better example would be一个更好的例子是

var person = database.GetMember(123) returns "Jesse Liberty"

not so that I can test the mock, but so that I can test code that depends on the database.不是为了测试模拟,而是为了测试依赖于数据库的代码。

Obvious, I know, but sometimes the brain just shuts down.很明显,我知道,但有时大脑会停止工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM