An overview of unit testing terminology ( stub vs mock , integration vs. interaction )?

前端 未结 5 1395
温柔的废话
温柔的废话 2021-01-30 04:33

I\'m using more unit tests in my projects and reading all the information I can online and am getting confused by a lot of the terminology. As a result I\'m probably using these

5条回答
  •  盖世英雄少女心
    2021-01-30 04:46

    When it comes to mocks vs. fakes vs. stubs, there are actually a few different ways that people interpret them. I usually borrow the meanings defined by Martin Fowler:

    1. Stub objects provide a valid response, but it's static -- no matter what input you pass in, you'll always get the same response.
    2. Fake objects act like the real object, but they go about it in a simpler way -- such as a DAO that uses a Map to store data instead of a real database.
    3. Mock objects are used in mock test cases -- they validate that certain methods are called on those objects.

    Interaction testing is a general term that refers to unit tests which ensure that the interaction between objects is correct (making sure that expected methods are called). This is opposed to state (or classical) testing, which doesn't care what happens in the methods, so long as the resulting state is correct. These types of testing are compared in Fowler's article that I linked above.

    Integration testing really isn't an aspect of unit testing, it is a level above the unit tests. It takes different units and verifies that they work together correctly.

提交回复
热议问题