I want to create a Spring Boot test for a Controller-class.
The method I want to test is:
private String statusQueryToken;
@RequestMapping("/onCompletion")
public String whenSigningComplete(@RequestParam("status_query_token") String token){
this.statusQueryToken = token;
I am unsure about how to test things in Spring Boot.
If I wanted to test that the field statusQueryToken
has been initialized with the @RequestParam("status_query_token")
, how would I go about doing this?
Thank you!
You can use Spring MockMvc
So try something like this:
There are several way you can approach this. My preferred way to test with the real tomcat instance.
There are different ways to test
1. Using Maven
This will generate the jar file with spring boot embedded with tomcat by default
This will run you spring app
Now Spring is up and running
2. Creating an executable jar (in absence on maven)
"Same effect as above"
Now open the browser or soap ui or fiddler or postmaster to send request to the controller
ex: GET method http://localhost:8080/myproject/onCompletion/hello
http://docs.spring.io/spring-boot/docs/current/reference/html/getting-started-first-application.html