Questions tagged [spring-boot-test]

Spring Boot provides utilities and annotations to help when testing your application.

Spring Boot provides a @SpringBootTest annotation which can be used as an alternative to the standard spring-test @ContextConfiguration annotation when you need Spring Boot features. The annotation works by creating the ApplicationContext used in your tests via SpringApplication.

Utilities: ConfigFileApplicationContextInitializer,EnvironmentTestUtils,OutputCapture and TestRestTemplate

for example

EnvironmentTestUtils.addEnvironment(env, "org=Spring", "name=Boot");

Docs: https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-testing.html

1399 questions
-1
votes
1 answer

WebTestClient instance doesn't see dependency of Controller as injected

I do some Test Configuration. I am surprised all is OK in first scenario but not in second. In scr/main/java, I got this Controller @RestController @RequestMapping("/v1") public class PostgressControllerSpringData { @Resource …
electrode
  • 205
  • 1
  • 4
  • 16
-1
votes
1 answer

java.lang.IllegalAccessException:.cannot access the member of class CrossOrigin with modifiers "private static"

I am trying to mock the controller class with some endpoints annotated with @CrossOrigin. it is giving this exception. Caused by: java.lang.IllegalAccessException: Class net.bytebuddy.description.annotation.AnnotationDescription$ForLoadedAnnotation…
-1
votes
4 answers

Unit testing save methods when return type is void

Is there any way to write unit tests for save methods in DAO layer when return type is void? I'm using Log4j, Junit in spring boot project. I've tried many ways to assert them. But since they aren't returning any value i wasn't able to assert…
user11638262
-1
votes
1 answer

Can someone explain orphanRemoval in Hibernate?

My question is not how work "mappedBy". I know, just indicates the owner of the relation. My question is how orphanRemoval works. And in my case I don’t use the indication mappedBy at all. I have the following entities: @Entity @Table(name =…
FreeOnGoo
  • 868
  • 1
  • 8
  • 26
-1
votes
1 answer

nullpointer exception in spring batch service layer is not injected

I am working on Spring Batch with Spring Boot. I am trying to inject service layer in ItemWriter but it is not working. I am getting service as null @Component public class DataWriter implements ItemWriter { @Autowired …
-1
votes
1 answer

Test failed in Gradle but working fine in Maven

test are running successfully with the maven and failing with Gradle I have a strange issue my spring boot application (version 2.1.0), which is using JPA(spring-boot-starter-data-jpa) for integrating with mysql db, there are integration test cases…
-1
votes
1 answer

Bean Injection not happening in controller when run via spring boot Test

I have created a spring boot web application with Rest based apis. My controller has a service which is autowired and injected when the application is started normally when run via main application. However if i run my integration test for that…
stallion
  • 1,901
  • 9
  • 33
  • 52
-1
votes
1 answer

Rest controller test with @WebMvcTest, Could not instantiate JAXBContext for PagedResources

I have some tests that were failing with Error creating bean with name 'entityManagerFactory' this answer solved it for me https://stackoverflow.com/a/47504698/6945345 but broke my Controller test with Could not instantiate JAXBContext for class…
-1
votes
1 answer

repository in rest controller catch error "Parameter 1 of constructor could not be found

I make JUnit tests for SpringBoot rest controllers. When i start tests i get the next error: I suppose it appears because of BookRepository class is autowired into Controller class. Because of legacy i cannot change this Controller class. What i…
jlemon
  • 95
  • 1
  • 9
-1
votes
1 answer

Selenium driver management in Springboot

I am trying to create a selenium framework using spring boot. What I am trying to accomplish it spring-boot should manage selenium driver creation, even when we run the test in parallel and if possible I want to avoid passing driver object in page…
Deepu Nair
  • 165
  • 5
  • 15
-1
votes
1 answer

Why aren't my test properties getting picked up by spring-boot when running mvn test

We have a Web application based on Spring-boot 2.0.x - recently enabled Spring-security for OAuth2 - security works, but I'm dealing with the aftermath of that in my project. My existing test cases are failing due to unsatisfied exception errors -…
JamesD
  • 679
  • 10
  • 36
-1
votes
2 answers

How to mock static access to spring-managed @Bean with Mockito?

I have a @Service bean that I need static access to: @Service public class MyBean implements InitializingBean { private static MyBean instance; @Override public void afterPropertiesSet() throws Exception { instance = this; …
membersound
  • 81,582
  • 193
  • 585
  • 1,120
-1
votes
1 answer

Spring Test Utils Autowired

I'm refactoring spring boot tests creating encapsulated classes with common behavior that will be injected in other tests. This classes has scope only in test package. Spring ignore slices that will not be used in test (which is great and by design…
Giovanni Silva
  • 705
  • 5
  • 17
-2
votes
1 answer

@Autowired annotation does not work in Junit5 Jupiter

With Junit 4 Autowired functionality was working fine. But once I migrated to Junit 5, I am not able to make Autowired work and there are lot of dependencies to make everything cover by mocking each object. Went through lot of websites and tried…
Chethan
  • 73
  • 8
-2
votes
1 answer

I can't manage to do a ComponentScan from a test packages to main packages

is there anyone who would know the way how to use a @ComponentScan(basePackages = {}) from class inside "test" directory to point on a packages in "main" directory. For instance: @Configuration @ComponentScan(basePackages =…
careful
  • 69
  • 8
1 2 3
93
94