Skip to main content

All Questions

0 votes
1 answer
71 views

Unable to pass multipart file through mockMvc

I am writing junit test for my request method. Im using mockMvc to trigger the rest request. When I run my test I get the error java.lang.NullPointerException: Cannot invoke "org.springframework....
manjosh's user avatar
  • 564
0 votes
0 answers
40 views

Actual response is returning null in unit test using JUnit 4.12

So, i'm trying to create a unit test since its my first time doing this and here is the code: package com.convergeict.shoppingcartservice.controller; import com.convergeict.shoppingcartservice.model....
drealmikaelson's user avatar
0 votes
1 answer
61 views

How to test private method passed in the supplier method of CompletableFuture.supplyAsync method?

I want to write JUnit test for a public method which uses CompletableFuture.supplyAsync to process some data and then save it to the DB. However, the supplier method passed contains a private method ...
Gargi Chaurasia's user avatar
2 votes
1 answer
250 views

How avoid loading unused beans in springBootTest?

I have a test class like this there I want to test only controller layer: @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) class MyControllerTest { @Autowired ...
gstackoverflow's user avatar
1 vote
0 answers
277 views

java.lang.ClassNotFoundException during execution of Contextloads() method in Spring Boot JUnit test case

We have a Spring boot v 2.7.x application, running on java 11. And we want to switch to java 17 and Spring boot 3.0.0. But now, when I am making the changes locally (IDE is IntelliJ), the following ...
Ivajlo Iliev's user avatar
1 vote
1 answer
69 views

How to use the bean created in the test to run an application?

I am writing test for an application where DataSource is created as a Bean when connecting to the DB2 Database. For the test I would like to use an in-memory H2 Database and call the main method to ...
Jeet's user avatar
  • 395
0 votes
1 answer
72 views

How to declare different properties in different methods of the same unit test class in Spring

I would like to have a single unit test class to test the initialization of a class @ConfigurationProperties("...") MyConfig, given different sets of configuration properties. For example: @...
Daniele Repici's user avatar
1 vote
0 answers
222 views

Writing a Spring Application context unit test without including test dependencies

I'm trying to write a junit test which tests the application configuration of my spring boot application. This test is meant to catch any runtime failures on app startup due to any number of reasons. ...
Natalie S's user avatar
2 votes
0 answers
354 views

Creating mock API using MockWebServer and calling by WebTestClient using spring boot 3 giving 404 error

I am working on a project to upgrade it to springboot 3.Now i am facing 404 NOT_FOUND error in junit test while mocking API using MockWebServer and WebTestClient.I am using 4.10.0 version of okhttp ...
sekhar's user avatar
  • 147
0 votes
0 answers
332 views

Junit test case for Rest template in Spring boot

I am using RestTemplate in a Spring project.Due to some reason i have created a RestTemplate Object inside a method. Example : public class Post { public Post(){ } public T postRequest(...
Rajat Sharma's user avatar
1 vote
1 answer
2k views

Read values from test yml files

I have a Spring Boot file with test YAML file application-test.yml located under src/test/resources: keycloak: endpoint: https://test.org Into JUnit test I tried to read the values using: import ...
Peter Penzov's user avatar
  • 1,048
1 vote
0 answers
296 views

migrating from @RunWIth(Springrunner::class) to @SpringBootTest with an H2 database (Junit4 to Junit5)

I'm upgrading spring-boot in a large project, and as a result the tests must be migrated from Junit4 to Junit5. From migration guides it sounded easy enough. Essentially, what I read over and over ...
UncleBob's user avatar
  • 1,335
0 votes
0 answers
728 views

Flyway scripts migration execution order while running test cases Junit

In our Spring boot Java project we are having flyway migration scripts. Below is our project structure, Project | | +-- src | | | +-- resources | +-- db.migration ...
Ronak Joshi's user avatar
  • 1,583
0 votes
0 answers
905 views

How do I create and use a spring boot testing utility class?

I want to create a utility class just for my tests that have some methods that all tests will use to reduce code duplication. Where do I create this class and how do I import it in my tests? Errors ...
haulvulgar's user avatar
1 vote
0 answers
223 views

Why container does not start automatically in Test?

I have the following class @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.MOCK) @RunWith(SpringRunner.class) @Testcontainers @ContextConfiguration(initializers = ...
smillis12's user avatar
  • 141

15 30 50 per page
1
2 3 4 5
9