July 2018
Intermediate to advanced
268 pages
7h 36m
English
Create a normal test class, as follows. Use the @Autowired annotation to inject the WebTestClient instance in your test class:
@RunWith(SpringRunner.class)@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)@FixMethodOrder(MethodSorters.NAME_ASCENDING)public class WebclientDemoApplicationTests { @Autowired private WebTestClient webTestClient; @Test public void getAllMovies() { System.out.println("Test 1 executing getAllMovies"); webTestClient.get().uri("/api/movie") .accept(MediaType.APPLICATION_JSON) .exchange() .expectStatus().isOk() .expectHeader().contentType(MediaType.APPLICATION_JSON) .expectBodyList(Movie.class); } @Test public void saveMovie() { System.out.println("Test 2 executing saveMovie"); Movie ...Read now
Unlock full access