spring-boot-test Questions
3
Solved
I have a @SpringBootTest class that has a rather complex mock definition setup with mocked return values.
Question: can I externalize @MockBean setups into an own class, so I could reuse the mock c...
Medical asked 12/4, 2021 at 7:13
2
I'm trying to wirte a unit test with @MockBean and JUnit 5 in a @WebMvcTest. Unfortunately it looks like @MockBean is ignored and it tries to set-up the full persistence layer, which fails and whic...
Forby asked 24/5, 2019 at 8:58
7
What am I doing wrong here? My understanding is Spring should autowire JavaMailSender the way its autowiring EventRepository. Any guidance?
application.properties and application-test.properties
...
Smail asked 5/3, 2017 at 14:5
3
Solved
I am trying to mock a function for various results. First, I mocked it for throwing an exception as follows:
Mockito.when(ClassName.methodName(Matchers.any(), Matchers.any())).thenThrow(new Except...
Bismuth asked 25/6, 2021 at 6:29
5
I am using spring data jpa in my spring boot project.
I am firing an JPQL query and using an projection to store the result of query.
My Projection :
public interface VeryBasicProjection {
String ...
London asked 13/11, 2017 at 6:13
2
Solved
I've generated a Spring Boot web application using Spring Initializr, using embedded Tomcat + Thymeleaf template engine, and package as an executable JAR file.
Technologies used :
Spring Boot 1.4...
Clausius asked 12/3, 2017 at 7:29
2
This method is empty in all my JUnit test cases. What is the use of this method?
Sonarqube is complaining
"Add a nested comment explaining why this method is empty, throw an UnsupportedOperationE...
Wincer asked 17/4, 2018 at 21:44
2
Solved
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 ...
Mercurial asked 14/4, 2021 at 11:54
3
Solved
My micro-service project based on spring-boot framework and all my unit test running with spring runner.
@RunWith(SpringRunner.class)
adding this annotations, imports the following library...
Escarpment asked 7/4, 2020 at 20:16
3
I wrote spring boot integration test and it is working. Here is the test config:
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = RANDOM_PORT)
@AutoConfigureMockMvc
@Transactional
pub...
Amphitryon asked 13/10, 2019 at 14:26
1
Solved
Hi I have a service class that contains mapper and repository:
@Service
public class ProductServiceImp implements ProductService {
@Autowired
private ProductRepository repository;
@Autowired
pr...
Deucalion asked 26/2, 2021 at 15:18
5
I am writing the test cases for my controller class which is a Spring Boot Application and I want to write the test cases only for controller class which invokes Service and Service to Repository. ...
Crandall asked 20/12, 2017 at 22:19
2
Solved
I am trying to write a unit test for a Kafka listener that I am developing using Spring Boot 2.x. Being a unit test, I don't want to start up a full Kafka server an instance of Zookeeper. So, I dec...
Expatriate asked 1/5, 2018 at 20:48
0
We have a Spring Boot app written in Kotlin. The problem is it hangs during Maven clean test while running context load test below.
Java: 14.0.1
Kotlin: 1.4.20
Spring boot:2.3.6.RELEASE
Spring clou...
Potage asked 30/11, 2020 at 17:33
1
I would like to disable security on endpoints during some unit tests.
I am using webflux functional endpoints so the below configuration does not work.
@AutoConfigureMockMvc(secure = false)
I des...
Griselgriselda asked 28/4, 2020 at 10:38
1
I am using MyBatis Spring Boot Starter version 2.1.3. Ever since moving to Spring Boot 2.2.7 (I've also tried 2.2.8 and 2.3.1 with the same results), I've had a problem using the MockBean annotatio...
Digestion asked 16/6, 2020 at 13:27
2
Solved
In most of the integration tests I'm using spring-boot-test(2.1.9.RELEASE) and spring-cloud-contract-wiremock(2.0.2.RELEASE). The test is starting up WireMock server based on : @AutoConfigureWireMo...
Continuate asked 16/1, 2020 at 11:12
1
I'm trying to set up testing environment with testcontainers and flyway in spring boot application. All this supposed to run via DinD scheme.
Current test example as follows:
import com.testapp.t...
Trichomoniasis asked 11/10, 2019 at 15:11
0
How to make Spring Boot Test under JUnit 5 resolve indented/hierarchical properties externalized on a YAML file?
I would like to write tests to validate some logic that depends on Environment.getPr...
Vaticination asked 17/9, 2020 at 22:44
1
I am trying to improve performance of medium tests in Spring Boot.
I am using the Spring Boot - testcontainers library.
For an individual test this works really well, with a few annotations I can g...
Cookbook asked 5/8, 2020 at 15:56
2
Solved
Here https://stackoverflow.com/a/52968130/10894456 is well explained why @DataJpaTest @SpringBootTest shouldn't be mixed in one application.
But barely explained the case when anyway need to test...
Extrude asked 24/4, 2019 at 20:33
3
Solved
My Service class is below, followed by its test -
@Service
public class MyServiceImpl implements MyService {
@Autowired
private RestTemplate restTemplate;
@Override
public StudentInfo getSt...
Toulouse asked 14/8, 2017 at 12:4
2
Solved
I need to test my autoconfiguration classes that make use of @ConfigurationProperties beans. I'm making use of ApplicationContextRunner as documented in https://docs.spring.io/spring-boot/docs/curr...
Mothball asked 5/12, 2019 at 8:24
1
Solved
Spring AOP + AspectJ: @AfterReturning advice wrongly executed while mocking(before actual execution)
In an integration test, my advice of @AfterReturning is wrongly executed while in the test I mock it to throw TimeoutException, and the arg passed to the aspect is null.
My advice:
@AfterReturning...
Mycorrhiza asked 2/7, 2020 at 14:36
0
After reading the JUnit doc again, I found it is good to use a @Nested inner class to group tests and finally display them in a tree structure in the test reports.
But when refactoring my PostContr...
Holstein asked 5/7, 2020 at 6:8
© 2022 - 2024 — McMap. All rights reserved.