What are mock objects in Java?

后端 未结 5 1732
死守一世寂寞
死守一世寂寞 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

    Mocking and Mock Objects is not specific to Java. Mock objects is a unit testing technique in which a code chunk is replaced by dummy implementations that emulate real code. This helps one to write unit tests targeting the functionality provided by the class under test.

    Check these articles which provide a very good introduction to the concept of mocking:
    Mock Objects (PDF)
    Endo-Testing: Unit Testing with Mock Objects (PDF)

    If you are looking for a mock framework for unit testing in Java, have a look at: Mockito. I have found it useful for my unit tests.

提交回复
热议问题