lundi 20 juillet 2020

How to create a unit test for a GET Rest service (Spring)

I developed an application which stores Books in MongoDb and the data is obtained from the console from the user and it's directly saved to MongoDb. And all the details of the Book objects are passed to the Angular frontend and I've used Spring to make the api.

@RestController
@RequestMapping("/api")
public class Controller {

@Autowired
    BookRepository bookRepo;

@GetMapping("/books")
    public List<Book> getBooks(){
        return bookRepo.findAll();
    }
}

The API is working without any error.(Checked using postman and data can be viewed from the Angular site)
Now I have to write a unit test for this Controller class. My knowledge on testing is very low please help me with this. Thanks in advance.

Aucun commentaire:

Enregistrer un commentaire