I'm trying to add an integration test to a Spring Boot Rest API application. The application consists of two controllers, and two services. I cannot mention the real names, but a simplification would be something like
- package companyname.controller
- company
- user
- package companyname.service
- company
- user
- some auxiliary packages under companyname like auth, dto, exception, model, etc.
The application has no DB but depends on certain services to bring data.
As I mentioned, I need to add testing, specifically integration testing. This has been very difficult because I don't have too much experience in Spring. So, trying to follow the following tutorial I create the following test.
package companyname;
import companyname.controller.CompanyController;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.test.context.TestPropertySource;
import static org.assertj.core.api.Assertions.assertThat;
@SpringBootTest
@TestPropertySource(
locations = "classpath:application-integrationtest.properties")
@ComponentScan(basePackages = {
"companyname.controller"
})
class CompanyControllerTest {
@Autowired
private CompanyController controller;
@Test
void contextLoads() {
assertThat(controller).isNotNull();
}
}
The problem is that I received this horrible error (the error is longer but I cut the repetitive parts)
org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'companyController' defined in file
path/to/project/server/build/classes/java/main/com/companyname/controller/CompanyController.class]:
Unsatisfied dependency expressed through constructor parameter 0:
Error creating bean with name 'companyService' defined in file [/path/to/project/server/build/classes/java/main/com/companyname/service/CompanyService.class]:
Can anyone point me to what I'm doing wrong?
Thanks in advance