"The Art of Unit Testing" Reading Notes----Interaction Testing Using Mock Objects

  • Three categories of unit tests

        1. Test based on return value;

        Test whether the return value of the method is as expected;

        2. State-based testing;

        Whether the changes to the state of the test method are as expected; for example, a new modification method is added to the test.

        3. Interactive test;

        A test of how one object sends messages (calls methods) to other objects. Interaction testing is required if the end result of a particular unit of work is to call another object.

 

  • Difference between mock object and stub

        definition 

        A mock object is a dummy object in the system that verifies that the object under test invokes the dummy object as expected and determines whether the unit test passes or not. Usually there is at most one mock object per test.

        A pseudo object can describe a stub or a mock object, depending on how it is used in the current test: if the pseudo object is used to test an interaction (assert it), it is a mock object, otherwise it is a stub.

 

        Note : In order to test the readability of the code and the convenience of diagnosing problems, a unit test can only have one mock object, that is, only one call of the mock object can be tested.

 

  • Isolation Framework: mockito

        Dynamic stubs and dynamic mock objects: mock(Interface1.class)

       For an introduction to the use of mockito, see: Mockito Tutorial

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325879213&siteId=291194637