From the course: Extending, Securing, and Dockerizing Spring Boot Microservices
Unlock the full course today
Join today to access over 23,300 courses taught by industry experts.
Restful API testing with JUnit
From the course: Extending, Securing, and Dockerizing Spring Boot Microservices
Restful API testing with JUnit
- [Instructor] This is a new class I added called RatingController. It invokes tourRatingService to look up the tour ratings in the database, which are converted into rating DTOs. The API is exposed as /ratings. This is RatingControllerTest. A pretty cool feature of Spring Boot is the ability to invoke an application controller's API in a real servlet environment without invoking the dependencies. In this case, tourRatingService is the dependency. Unlike other unit tests that directly invoke Java methods, this will actually invoke the URL. But how does it do that? It's basically an integration test, which starts up the entire Spring Boot web context but the tourRatingService is mocked out. The API is invoked by a RESTful web service client. Let's look at the annotations here at the beginning. Something is new and it's webEnvironment equals RANDOM_PORT. Instead of port 8080, which may already be in use, at runtime,…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.