Java – Cactus and mock object (jmock, easy mock)

I'm confused about cactus and jmock (easy mock)

Who can answer the following questions?

>When to test with cactus? > When to test without cactus? > When to test with mock objects? > When not to test with mock objects?

Solution

Well, there is no objective answer to this question, but the simulation object is about the behavior of the test code, but it can't tell you whether you interact with the container correctly

Cactus runs your code in the container, so it is actually more like an integration test, but what it tells you is that your code actually interacts with the container correctly (what it sends is legal, and what it returns is real)

In short, mock tells you that if you want behavior x, you will get behavior X. cactus tells you that behavior x actually gets the expected results in the container

Which one you use depends largely on the task you try to accomplish through testing If you want to do more TDD, the simulation method is the way you have to go You do a separate prototype design to see if you have enough understanding of how the container writes code, then carry out unit test, and then carry out integration test / acceptance test to ensure that everything is normal

However, if you are trying to do more traditional unit tests, and you try to test the edge situation and behavior with different values, testing with simulation won't tell you much because a large part of your containers are lost

I prefer the mock method at present, but if I want to go back to cactus, there will be more invariants in the test container. In this way, if we upgrade the container, we will know that there are no important changes in the working mode of the container that will affect our code

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
分享
二维码
< <上一篇
下一篇>>