Unit Testing--mockito: A powerful simulation test framework for Java development __java

Source: Internet
Author: User

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;
public clas S counter {
'      public counter () {
[      }
  & nbsp;  public 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.