Http://www.oschina.net/translate/mockito-a-great-mock-framework-for-java-development
introduce This article introduces some basic concepts of the simulation test framework Mockito, introduces the advantages of the framework, and explains the Java example of applying Mockito. The concept of impersonation (mock) Outside the world of software development, the term "mock" refers to imitation or emulation. So you can interpret a "mock" as a stand-in, a substitute. References to "mocks" in software development are generally understood as mock objects or fake. Translators Note: Mocks, and so on, represent abstract classes of objects being emulated, and you can interpret fake as instances of mocks. I do not know if this is accurate: |
|
Fake are often used as substitutes for the dependencies of the class being tested.
Ranking definition |
Dependencies – A dependency is a class in an application that performs its intended function based on another class. The dependencies usually exist in the instance variables of the dependent class. |
|
Test class – When writing unit tests, the term "unit" usually represents a separate class and the test code written for it. The class being tested refers to the class in which the test is taken. |
|
|
Why do I need to simulate? When we first started programming, the objects we wrote were usually independent. Classes such as Hello World do not rely on other classes (except System.out) and do not manipulate other classes. But in reality, software is full of dependencies. We will write the Operation class based on the service class, and the service class is based on the data Access Class (DAOs), Go down in turn. |
|
The idea of the
Unit test is that we want to test the code without involving dependencies. This test allows you to test the validity of your code by ignoring the dependencies of your code. The core idea is that if the code works as designed, and the dependencies are normal, , then they should be working properly at the same time. The following code for is an example of:
- |
import java.u Til. ArrayList; |
|