Are Spring's MockMvc used for unit testing or integration testing?

前端 未结 2 671
时光取名叫无心
时光取名叫无心 2020-12-23 15:26

Spring has 2 setups for the MockMvc:

  1. Standalone setup
  2. WebApplicationContext setup

In general what kind of testing is MockMvc used for?

2条回答
  •  执笔经年
    2020-12-23 15:54

    I would say that both methods are for integration testing, but standalone force you to specify which controller you are testing.

    WebApplicationContext setup is loading whole context, so you don't care where is specific controller which serves for example /people POST requests.

    So I would recommend using WebApplicationContext setup for testing your REST API in terms of interface which application need to work with. You dont couple test with actual code then + you are documenting the way the app should behave.

提交回复
热议问题