매우 초보적인 문제지만 지나칠 수 없는 문제입니다. 기본 Spring Boot 앱과 클라우드 아틀라스 인스턴스에 연결하는 Spring Data MongoDB 리포지토리 하나가 있습니다. 문제는 내 Spring Boot 테스트에서 내 리포지토리가 자동 연결되지 않고 포함된 MongoDB 인스턴스가 생성되지 않는다는 것입니다. Spring Boot 앱을 시작하고 기본 클래스에서 리포지토리를 autowire하면 작동합니다. 테스트에서 작동하지 않는 이유는 무엇입니까?
이것은 내 테스트 클래스입니다.
@DataMongoTest
@ExtendWith(SpringExtension.class)
public class SampleServiceTest{
@Autowired
private SampleRepository sampleRepository;
@Test
public void shouldCreateSample(){
sampleRepository.save(new Sample());
}
}
이것은 내 pom.xml입니다.
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.2.RELEASE</version>
<relativePath></relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>com.comand</groupId>
<artifactId>business-owner-service</artifactId>
<version>1.0-SNAPSHOT</version>
<description>API Gateway</description>
<properties>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
<dependency>
<groupId>de.flapdoodle.embed</groupId>
<artifactId>de.flapdoodle.embed.mongo</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-parent</artifactId>
<version>Greenwich.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>