WebMvcTest yog dab tsi?
WebMvcTest yog dab tsi?

Video: WebMvcTest yog dab tsi?

Video: WebMvcTest yog dab tsi?
Video: Potemkinsche Dörfer - Unit Testing mit JMockit 2024, Kaum ib hlis
Anonim

@ WebMvcTest annotation yog siv rau Spring MVC xeem. Nws lov tes taw tag nrho nws pib-configuration thiab siv xwb configuration cuam tshuam rau MVC xeem. Cov WebMvcTest annotation auto-configure MockMvc piv txwv li. Siv EmployeeRESTController.

Yog li ntawd, MockMvc siv rau dab tsi?

Lub plawv ntawm lub caij nplooj ntoos hlav-test-mvc yog chav kawm hu ua MockMvc uas tau siv sau cov ntawv xeem rau txhua daim ntawv thov siv los ntawm kev siv Spring MVC. Peb lub hom phiaj yog los tsim ib qho tshiab MockMvc kwv yees los ntawm kev siv cov kev siv ntawm MockMvcBuilder interface.

Tsis tas li ntawd, AutoConfigureMockMvc yog dab tsi? @ AutoConfigureMockMvc Tso cai rau txhua qhov kev teeb tsa nws pib cuam tshuam nrog MockMvc thiab tsuas yog MockMvc. Ntxiv dua thiab, qhov no yog ib feem ntawm tag nrho nws pib-configuration. Nws suav nrog cov nram qab no nws pib-configuration (saib spring.factories) # AutoConfigureMockMvc auto-configuration imports org. springframework.

Ib yam li ntawd, kev siv @SpringBootTest yog dab tsi?

Cov @ SpringBootTest annotation tuaj yeem yog siv thaum peb xav tau bootstrap tag nrho lub thawv. Cov lus piav qhia ua haujlwm los ntawm kev tsim ApplicationContext uas yuav raug siv hauv peb qhov kev xeem. Peb ua tau siv lub webEnvironment attribute ntawm @ SpringBootTest los teeb tsa peb lub sijhawm ua haujlwm ib puag ncig; peb siv WebEnvironment.

Lub caij nplooj ntoos hlav khau raj MockMvc yog dab tsi?

MockMvc tau nyob ib ncig ntawm txij li thaum Caij nplooj ntoos hlav 3.2. Qhov no muab txoj hauv kev zoo los thuam Caij nplooj ntoos hlav MVC rau kev sim MVC web applications. Los ntawm MockMvc , koj tuaj yeem xa cov lus thuam HTTP rau tus maub los thiab sim seb tus maub los ua li cas yam tsis tau khiav tus maub los hauv lub server.

Pom zoo: