All Questions
Tagged with spring-boot junit
1,008
questions with no upvoted or accepted answers
8
votes
1
answer
570
views
What is the equivalent of MockHttpServletRequestBuilder for websockets tests in Spring
What is the equivalent of MockHttpServletRequestBuilder for websockets. i.e. In a situation where I want to test Websockets., I would like to test a long running websocket application and avoid the ...
7
votes
1
answer
2k
views
SLF4J: Class path contains multiple SLF4J bindings slf4j-test vs logback-classic
I know what you're all gonna say, this is a duplicate question, etc... But it is not. Because I have done the exclusion configurations suggested in slf4j-test and I still get the error below whenever ...
6
votes
1
answer
2k
views
Unit Test for Spring Asyncronous post request is returning exception(async started expected as true but false)
My POST request is Asynchronous because I am using spring-data-rest. Now I am having issue when trying to write a test case for the POST request. The exception is "Async started expected: true but was:...
6
votes
0
answers
1k
views
Failed to load ApplicationContext JUnit
I'm doing a method testing using REST Assured and run it with JUnit. But when I run the test there is error that said Failed to load ApplicationContext.
The test class
@SpringBootTest(...
5
votes
0
answers
3k
views
@SpringBootTest resulting in 'No tests found for given includes'
I have simple unit test which starts my app and tests that certain services have been instantiated. Kind of just a sanity check.
However, these tests are not being run in my full test suite, and when ...
5
votes
0
answers
1k
views
spring boot junit test + @transactional propagation required_new
I want to test a loop that save into my DB.
I've set up a database in memory and I've loaded my scenario.
I've a basic test class named BasicInitTestlike this
RunWith(SpringJUnit4ClassRunner.class)
@...
4
votes
0
answers
3k
views
Invoking the beforeTestMethod method on PowerMock test listener - Junit
we upgraded the springboot version 2.5.14 to 2.7.5 , all of a sudden the below junit
started failing.
@RunWith(PowerMockRunner.class)
public class StarterApplicationTest {
@Test
@...
4
votes
0
answers
1k
views
SpringBoot Test JPA got "no session" exception when FetchType=Lazy
I'm junit testing inside the below function:
@Test
public void testQueryUser(){
User user1 = userRepository.findById(12L).orElse(null);
assertThat(user1)
....
4
votes
0
answers
1k
views
Maven doesn't run unit tests in a multi-module project with Spring Boot
Maven supports multi-module applications by having the child modules point to the parent module, but Spring Boot wants it's parent to be
<parent>
<groupId>org....
4
votes
0
answers
852
views
How to Unit Test Spring Boot App with Spring Security
I have a simple application that I have setup with spring security using a custom MySql Database. You can check out the complete app on github. Now the problem is I'm writing test cases for it and ...
4
votes
1
answer
3k
views
Error testing with Spring Boot Test
I'm trying to implement a simple unit test on my service. The code of my test class is the following:
@RunWith(SpringRunner.class)
@SpringBootTest
public class UserServiceTest {
@Mock
...
4
votes
0
answers
180
views
How to get entity relationship with annotations using testing class?
I have created a simple Spring-boot application with two entities as Company.java and User.java. These two has @OneToMany relationship. And I have a created a test file for generating typescript file ...
3
votes
1
answer
2k
views
Integration test using testcontainers((MongoDB issues)) are failing after upgrading to SpringBoot 2.6.6
I have updated SpringBoot version from 2.1.6 to 2.6.6 and after starting integration tests with testcontainers I am receiving below errors:
First error is:
13:25:08.793 [main] ERROR o.s.boot....
3
votes
1
answer
6k
views
Mockito verify number of invocations in spring boot test
I'm trying to verify that a mocked method (fileSenderService.sendFile) was called exactly 2 times. For whatever reason Mockito never fails the test, no matter what number of invocations are expected. ...
3
votes
1
answer
478
views
Stackoverflow error while using MockitoMVC with Junit in Spring App
I am trying to test my Spring Application which consists of JWT auth with Junit and Mockmvc. Signup test is working as expected. But when trying to test login, StackOverflowError is displayed. Inside ...