From the course: Extending, Securing, and Dockerizing Spring Boot Microservices

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Restful API testing with JUnit

Restful API testing with JUnit

From the course: Extending, Securing, and Dockerizing Spring Boot Microservices

Start my 1-month free trial

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,…

Contents