课程: Complete Guide To Java Testing with JUnit 5 & Mockito
今天就学习课程吧!
今天就开通帐号,24,600 门业界名师课程任您挑!
Test Spring controllers
- [Instructor] Let's finish up our testing for this user application by adding a test class for the controller. Like with our hello controller, we'll annotate this class with WebMvcTest and we'll pass in our UserController class. We'll also autowire the MockMvc. The UserController has the user service as a dependency, so we'll use Mockito to mock its interactions. We use the MockBean annotation here instead of Mock because we want to replace the user service within the Spring application context. We want it to be this mock. Within this test class, we'll also create a user field that we can use in several tests. It'll be our John Doe user. Now let's write a test for the createUser endpoint. When we create a user, we'll be interacting with the saveUser method on the User service, so let's stub that method. Then we'll make a post request on the MockMvc object. We'll also want to send a request body, so let's add that. It'll be in JSON format. The content will be the details of the user…
内容
-
-
-
-
-
-
-
-
-
-
(已锁定)
Walk through a basic Spring Boot application3 分钟 53 秒
-
(已锁定)
Write your first Spring Boot test3 分钟 43 秒
-
(已锁定)
Test Spring data repositories6 分钟 1 秒
-
(已锁定)
Test Spring services4 分钟 9 秒
-
(已锁定)
Test Spring controllers5 分钟 58 秒
-
(已锁定)
Integration testing with Spring Boot10 分钟 40 秒
-
(已锁定)
Best practices and tips for testing Spring Applications2 分钟 9 秒
-
(已锁定)
Challenge: Test a Spring weather application1 分钟 8 秒
-
(已锁定)
Solution: Test a Spring weather application16 分钟 37 秒
-
(已锁定)
-