Questions tagged [springrunner]
42 questions
19
votes
4 answers
Is there any special configuration to use SpringRunner with junit5?
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:
import…

Ilan Miller
- 323
- 1
- 3
- 11
4
votes
2 answers
Is it OK to use SpringRunner in unit tests?
We are arguing about this approach with my colleagues. They say to use SpringRunner only on integration or functional levels.
The question is what pros and cons of using it in level below?
For example I have simple bean:
public class…

SoulCub
- 467
- 8
- 17
4
votes
2 answers
Exclude ApplicationStartup Event listener when testing
I recently added an ApplicationStartup class to my SpringBoot project
@Component
public class ApplicationStartup
implements ApplicationListener { ...
It implements ApplicationListener.
Now when I run my old JUNit tests…

ed4becky
- 1,488
- 1
- 17
- 54
3
votes
0 answers
Tomcat initialized and starts on different ports
I have a problem with my end to end test:
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
@TestPropertySource(locations = {"classpath:test.properties"})
public…

MatWdo
- 1,610
- 1
- 13
- 26
3
votes
2 answers
SpringBoot @MockBean and @WebMvcTest does not work
Controller.java
@RestController
public class Controller {
@Autowired
private UserService userService;
@Autowired
private BookService bookService;
//Below userService implementation
@PostMapping(value = "/addNewUser",…

Kacu
- 438
- 4
- 23
3
votes
1 answer
SpringApplicationBuilder is not loaded during integration tests with JUnit SpringRunner
It's my first question ever on stackoverflow.com.
Lately I have been looking for a way to change how Spring Boot (2.x) names its beans, created via @Component (etc) annotation.
I have found the SpringApplicationBuilder class, which thankfully allows…

Fantazjatyk
- 31
- 3
2
votes
0 answers
Failed to create Environment bean in SpringRunner
I need to read properties for unit testing in one of the test class using Environment bean but spring is failed to create environment bean.
@RunWith(SpringRunner.class)
@TestPropertySource(locations = "/application-test.properties")
public class…

Babu Patil
- 31
- 3
2
votes
4 answers
Error while running spring boot tests, SpringRunner.class Not found
When I try to invoke JUnit test cases from my Spring Boot Application, I am getting following error:
I am using this annotation in my Test class.
@RunWith(SpringRunner.class)
After I add JUnit library from project dependencies, it gives me…

Raghavendra Chary Desoju
- 55
- 1
- 2
- 6
2
votes
1 answer
Why does @SpringRunner test reinitialize the class on each test?
I am using @PostConstruct to do some initial setup before running tests, but it seems like the @PostConstruct method is running on each and every test, instead of only once after the test class is initialized. I also see that the constructor is…

Hung Tran
- 73
- 1
- 5
2
votes
1 answer
How do I run all @DataJpaTest classes at once?
I am able to run each @DataJpaTest separately from eclipse.
My @DataJpaTest is something like below:
@RunWith(SpringRunner.class)
@DataJpaTest
@Import(UserDataOnDemand.class)
@AutoConfigureTestDatabase(replace = Replace.NONE)
public class…

Krish
- 1,804
- 7
- 37
- 65
1
vote
1 answer
UnsatisfiedDependencyException when making JOOQ tests on springboot
I have this basic CRUD API using springboot version 2.7.10 and JOOQ 3.14 and it has some previously written tests but they are not working, since i don't have experience with JOOQ and tesccontainer i can't pinpoint what is the problem but i will…

Paulo Henrique
- 100
- 9
1
vote
2 answers
camunda unit testing with MockitoJUnitRunner and SpringRunner
I am writing test cases for Camunda workflows. I am using SpringRunner @RunWith(SpringRunner.class) and have the following properties in Test class required for the test execution
@Autowired
private ProcessEngine processEngine;
…

Klose
- 323
- 5
- 17
1
vote
0 answers
Not able to write junit test case for jpa specification
I have a PersonServiceImpl class in which I am fetching record from repository like this.
personRepo.findAll(**new Specification**() {
@Override
public Predicate toPredicate(Root root, CriteriaQuery>…

Santosh Singh
- 71
- 4
1
vote
1 answer
In @SpringBootTest, is there a way to have SpringRunner.class and Theories.class co-exist?
This is hopefully a simple question.
I have a Spring Boot Test.
The annotations are:
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Main.class)
@TestPropertySource(locations { "myproperties.properties" })
I've got a test that I'd love to…

newbo
- 163
- 1
- 9
1
vote
1 answer
Mocked method return value is null in Spring Boot @WebMvcTest
The below test fails with: org.json.JSONException: Unparsable JSON string.
I tried various variations of the mocking the saveAndFlush method
// doAnswer(returnsFirstArg()).when(this.shipwreckRepository).saveAndFlush(shipwreck);
// …

rok
- 9,403
- 17
- 70
- 126