user3257736 user3257736 - 1 year ago 44
Java Question

Testing a Spring Boot application?

I want to create a Spring Boot test for a Controller-class.

The method I want to test is:

private String statusQueryToken;

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
has been initialized with the
, how would I go about doing this?

Thank you!


There are several way you can approach this. My preferred way to test with the real tomcat instance.

    public class TestClass() {
        private int port;
    private RestTemplate restTemplate;

   public <T> T get(String path, Class<T> responseType, Object... pathVariables) {
        return restTemplate.getForEntity(path, responseType, pathVariables).getBody();