What are mock objects in Java?

后端 未结 5 1736
死守一世寂寞
死守一世寂寞 2020-11-30 06:18

I like to know what mock objects are in Java. Why do we create them and what are their uses?

5条回答
  •  我在风中等你
    2020-11-30 06:49

    Quote from here: http://easymock.org/

    Unit testing is the testing of software units in isolation. However, most units do not work alone, but they collaborate with other units. To test a unit in isolation, we have to simulate the collaborators in the test. A Mock Object is a test-oriented replacement for a collaborator. It is configured to simulate the object that it replaces in a simple way.

    for example, if you are wanting to test http calls you will need to create real-life request objects,complete with all their dependencies. This can often require a lot of effort, hence the use of mocked objects which provide a quicker path to creating an accurate rendition of the object you need, without the long chain of dependencies.

提交回复
热议问题