Spring RestServices Testing

Course Number:


Course Duration:
3 Days


Course Objectives:
Course Outline:

JUnit 4  Overview

  • Lifecycle annotations
  • assertEquals, assertTrue, assertFalse, AssertSame
  • Testing exceptions, using @Rule
  • Hamcrest Matchers and assertThat
  • Parameterized Tests
  • Theories

JUnit 5 Overview 

JUnit Vintage and Jupiter

  • Lifecycle annotations
  • Grouped assertions and nested Grouped Assertions
  • Exception testing
  • @EnableOn, @DisableOn, @EnableIf
  • @ParameterizedTest using method sources

Stubs and Mocks

Making Code Testable

  • Creating Fake Dependencies


  • Creating Mock Objects
  • MockitoAnnotations
  • @Mock
  • @InjectMocks
  • Partial Mock or @Spy
  • ArgumentCaptors @Captor

Spring Boot, Testing Controllers and RestControllers

Core Spring testing

  • JUnit4
    • @RunWith(SpringJUnit4ClassRunner.class)
    • @ContextConfiguration
  • JUnit5
    • @ExtendWith(SpringExtension.class)
    • @ContextConfiguration

Testing Running Spring Boot Services

  • RestTemplate
    • getForObject, getForEntity
    • postForEntity
    • exchange
    • Setting headers
    • Consuming a Response
    • Content Negotiation
  • WebClient (Spring 5)
    • Building a ResponseSpec for Get and Post requests
    • WebFlux and using Mono in our tests
    • Content Negotiation with ResponseSpec
    • Subscribing to the Mono of the Response
    • Using retrieve and exchange
  • Spring Services Unit testing
    • @WebApplicationConfiguration
      • MockMvcBuilders and MockMvcRequestBuilders
      • Standalone Controller and WebApplicationContext
    • ResultActions, expected results
    • Viewing the Response, MockMvcResultMatchers.JsonPath
    • @MockBean, mocking dependencies of the ApplicationContext
    • @WebMvcTest
    • Testing a JPARepository with MockObjects
  • Integration Testing with @SpringBootTest
    • TestRestTemplate
    • Get and POST Requests
  • Testing a Spring Cloud Eureka Registered Service
    • Disable Eureka Registration (Discovery Client)
    • Using Mock Objects
    • Testing a Feign Client Service

Integration Testing with Cucumber JVM

  • Gherkin basics
  • Feature and Scenario using Mocks
  • Scenario Outline
  • Testing Spring Boot Services with Cucumber and @SpringBootTest

Related Posts

About Us

IT Training, Agile Ways of Working and High Impact Talent Development Strategies

Let Us Come to You!

Classes recently delivered in: Atlanta, Boston, Chicago, Columbus, Dallas, Detroit, Indianapolis, Jerusalem, London, Milan, New York, Palo Alto, Phoenix, Pittsburgh, Portland, Raleigh, San Antonio, San Diego, San Francisco, San Jose, Seattle, Springfield, Mass., St. Louis, Tampa and more!