I need to test old Spring Boot Java application (version of Spring Boot 1.2.7, Java 1.8) and I don’t want to change Spring version (because the application is very voluminous and then I will have to refactor the code very much). I’d like to apply to input of my desktop application different table column types and test that application determines
Tag: spring-boot-test
How to setServletPath() in Spring Junit WebTestClient?
This creates a MockHttpServletRequest that is send to the @RestContoller servlets. Problem: my servlets make use of HttpServletRequest.getServletPath(), but which is always empty using the WebTestClient approach above. Question: how can I explicit set the servletPath in my junit tests? Answer I could solve it as follows, but as this is really hacky, I’d still appreciate a proper solution.
NullPointerException Mock when use RestTemplate
I am new to using mockito and I have a problem. I wrote a controller test and it uses restTemplate to get data from another api, but when I run the test, the variable of this type is null. In result NullPointerException. What could be the problem? Controlle: Test: Answer This is because you don’t have restTemplate, so restTemplate is
Lombok generated constructor can not implicit autowire in SpringBootTest
I want to inject class A into class B through the constructor. But the following error is thrown when I run the test. Answer The problem is already raised in issue#22286, due to difference in autowire handling between Spring and Spring integration with JUnit. Which failed to do implicit autowire on constructor without @Autowired. So as a workaround, add onConstructor
SpringBootTest for an arbitrary ApplicationConfiguration class to test the reading of the application.yml file
I would like to learn how to write a SpringBootTest for an existing ApplicationConfiguration class for the purpose of testing the functionality of reading the application.yml file. I would be happy with java or groovy. I am not able to share the existing ApplicationConfiguration class, so I would gladly accept any example offered that starts with an existing ApplicationConfiguration that
Junit Force to throw Exception on method call
I am trying to throw the exception whenever simpleJdbcCall.execute(namedParameters) called but I see it is not throwing the error, is there something i am missing here ? Here is my class here is my Junit Class Answer When writing spring-boot integration test you should inject the mock beans using @MockBean annotation You can a follow some of the examples here
spring boot – integration test autowired interface no such bean found
I have a spring-boot app that now needs to support multiple Object stores and selectively use the desired store based on the environment. Essentially what i have done is create an interface that each store repository then implements. I have simplified the code for the examples. I have created 2 beans for each store type based on the spring profile
How to set up different responses for the same request to MockServer?
i’m having an issue when setting up the MockServerClient for multiple responses with the exact same request. I read that with expectations with “Times” this might be done, but i coulnd’t make it work with my scenario. If you call the service with this JSON (twice): The first response should be “passed true”, the second “passed false” Response 1: Response
Attribute ServerContainer not found in ServletContext
In my Spring boot application i use also websockets. Everything works fine, as expected in production. Now i started to create UnitTests with Spring-Boot-Test. Every time i start a @SpringBootTest , i get following exception (shortened): Long Version Spring Websocket Config Class POM.XML Spring Application Class Typical Failing Test Problem The Problem is, the actual Test never comes to the
Unit Test or Integration Test in Spring Boot
I looked various tutorial online related to testing in Spring Boot and got confused by the way the tests were referred. Some articles refer to controller tests that use @WebMvcTest annotation as …