Ich versuche zum ersten Mal, einen Test für meine API zu schreiben und erhalte die Fehlermeldung java.lang.AssertionError: No value at JSON path „$.id“ . Ich habe meine API mit openApi getestet und es hat gut funktioniert. Hier ist meine Codeform-Testdatei
Ich versuche zum ersten Mal, einen Test für meine API zu schreiben und erhalte die Fehlermeldung java.lang.AssertionError: No value at JSON path „$.id“ . Ich habe meine API mit openApi getestet und es hat gut funktioniert. Hier ist meine Codeform-Testdatei [code] package com.RCTR.usersys; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import java.util.List; import static org.hamcrest.Matchers.*; import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.http.MediaType; import org.springframework.test.context.bean.override.mockito.MockitoBean; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder; import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; import com.RCTR.usersys.controller.UserController; import com.RCTR.usersys.model.User; import com.RCTR.usersys.service.UserService; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectWriter;
@AutoConfigureMockMvc @WebMvcTest(UserController.class) class UserControllerTest {
private final List users = List.of( new User(1L ,"Laur","Pinzaru","laur@pinz.com" ), new User(2L ,"Petru","Gologan","petru@gologan.com" ), new User(3L ,"Luca","Pinzaru","luca@pinz.com" ) );
@Test public void getAllUsersSuccess() throws Exception{
} } [/code] Das Problem tritt bei der Methode createUserSucces auf [b]und das ist mein Controller[/b] [code]package com.RCTR.usersys.controller; import java.util.HashMap; import java.util.List; import java.util.Map;
@RestController @RequestMapping("/api/v1/") public class UserController {
private final UserService userService;
public UserController(UserService userService) { this.userService = userService; }
@PostMapping("/user") public User saveUser(@RequestBody User user){ return userService.saveUser(user); }
@GetMapping("/users") public List getAllUsers(){
return userService.getAllUsers(); }
@GetMapping("/users/{id}") public ResponseEntity getUserById(@PathVariable("id")Long id){ User user = null; user = userService.getUserById(id); return ResponseEntity.ok(user); }
@PutMapping("/users/{id}") public ResponseEntity updateUser(@PathVariable("id")Long id,@RequestBody User user){ user = userService.updateUser(id,user); return ResponseEntity.ok(user); }
Ich versuche zum ersten Mal, einen Test für meine API zu schreiben und erhalte die Fehlermeldung java.lang.AssertionError: No value at JSON path „$.id“ . Ich habe meine API mit openApi getestet und...
Ich versuche zum ersten Mal, einen Test für meine API zu schreiben und erhalte diesen Fehler
java.lang.AssertionError: JSON path „$“ Erwartet: eine Sammlung mit Größe , aber: Sammlungsgröße war . Ich...
Ich versuche zum ersten Mal, einen Test für meine API zu schreiben und erhalte diesen Fehler
java.lang.AssertionError: JSON path „$“ Erwartet: eine Sammlung mit Größe , aber: Sammlungsgröße war . Ich...
Ich versuche, Web-API2, JWT, Microsoft.IdentityModel.jsonWBtokens 5.2.422 und die in diesem Artikel beschriebene Token-Validierungslogik zu verwenden: /p>