Java – simulating objects in JUnit tests – best practices?

Do you think it's best to laugh at people in JUnit testing? I don't see much advantage Of course, it makes sense if you have a database that should not be considered in your test, but why not inject other implementations of the component (if using spring) An object factory test will make this easy I don't have much experience (we're using mockito), but I've seen that the application code has been modified to make some properties shameful! Test cases should not eliminate this change in production code in my objection

What do you think of this topic? In this case, are you laughing at your object or why not?

Solution

The idea of ridicule is that you completely isolate what you are testing Then, when the test fails, you can determine the problem without traversing the entire class dependency tree If you test the behavior of multiple classes together, this is not a real unit test

The object factory for testing may assume that objects are made using the stubbed method, while the mocking framework is essentially a general object factory for testing But irony offers more than stubs – a difference Martin Fowler details here: http://martinfowler.com/articles/mocksArentStubs.html.

If you find it hard to ridicule and you find yourself doing a lot of things, this is a typical example of TDD, which tells you that your design can be improved

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>