简体   繁体   English

关于与其他方法组合的存根方法的问题

[英]Question about stubbing method composed with other methods

   def foo
     a & b & c & d
   end

And it is very important for application logic, so I have to write good test for it. 这对于应用程序逻辑非常重要,因此我必须为此编写良好的测试。 Methods a,b,c,d are already tested. 方法a,b,c,d已被测试。 Should I prepare full data to make a,b,c,d work and return requested values, or stubbing in this case is enougth? 我是否应该准备完整的数据以进行a,b,c,d工作并返回所请求的值,或者在这种情况下进行存根运算是值得的?

A unit test should only test the method under test, ie foo. 单元测试只能测试被测方法,即foo。 This means, you should stub a, b, c and d. 这意味着,您应该将a,b,c和d存根。
To make it of any use, you should make sure, that you cover all corner cases that could result from the return values of those methods. 为了使它有用,您应该确保覆盖了所有可能归因于这些方法的返回值的情况。

如果您真的想对此进行全面测试,我将编写两种自动测试: 单元测试 ,它将a,b,c和d作为存根接收;以及一个集成测试 ,该测试将确保所有逻辑都可以很好地协同工作。没有集成问题。

I appreciate your desire to test thoroughly, but a unit test of this using stubs would only test that the & operator works properly. 非常感谢您希望进行全面测试,但是使用存根对此进行单元测试只能测试&运算符是否正常运行。 That operator is not your code. 该运算符不是您的代码。

If you use mocks instead of stubs, it would at least test that all the methods are called, but that's really only sort of a documentation test. 如果使用模拟而不是存根,它将至少测试所有方法都被调用,但这实际上只是一种文档测试。

An integration test using data might however be useful. 但是,使用数据进行集成测试可能会有用。

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

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