Test
  • Introduction
  • Regression Testing
  • Unit Test
  • reflection
  • terminology
  • Defect Life Cycle
  • NullVSNotNull
  • @Before VS @BeforeEach VS...
  • JUnit Runner
  • run only functional test or integration test
  • cucumber/tags
  • cucumber/ options
  • cucumber/runwith
  • parallel cucumber test
  • cucumber/some eg
  • Hamcrest for testing
  • continuous integration
  • work flow for functional test
  • unit test for server side
  • other
  • Mock
  • jacoco&mutation
  • PowerMockito
  • performance test
Powered by GitBook
On this page

Was this helpful?

unit test for server side

Previouswork flow for functional testNextother

Last updated 5 years ago

Was this helpful?

Server-Side Tests

There are two main strategies we can identify in Spring: writing Controller tests using the MockMVC approach, or making use of RestTemplate. The first strategy(MockMVC) should be your preferred one if you want to code a real Unit Test, while RestTemplate should be used if you intend to write an Integration Test. The reason is that with MockMVC we can fine-grain our assertions for the Controller. RestTemplate, on the other hand, will use the Spring’s WebApplicationContext (partly or fully, depends on using the Standalone mode or not). Let’s explain these two strategies in more detail.

MockMVC:

https://thepracticaldeveloper.com/2017/07/31/guide-spring-boot-controller-tests/
https://spring.io/guides/gs/testing-web/
https://springframework.guru/unit-testing-spring-mvc-spring-boot-1-4-part-1/
https://howtodoinjava.com/spring/spring-restful/spring-restful-client-resttemplate-example/
https://spring.io/guides/gs/testing-web/
https://www.luckyryan.com/2013/08/24/unit-test-controllers-spring-mvc-test/
https://thepracticaldeveloper.com/2017/07/31/guide-spring-boot-controller-tests/
http://www.baeldung.com/spring-boot-testresttemplate
https://www.petrikainulainen.net/programming/spring-framework/unit-testing-of-spring-mvc-controllers-normal-controllers/