[문제 발생]
Caused by: java.lang.IllegalStateException: Failed to replace DataSource with an embedded database for tests. If you want an embedded database please put a supported one on the classpath or tune the replace attribute of @AutoConfigureTestDatabase.
package com.extension.persistence;
import com.extension.domain.entity.Extension;
import com.extension.domain.entity.ExtensionType;
import jakarta.persistence.EntityManager;
import jakarta.persistence.PersistenceContext;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import java.util.Optional;
import static org.junit.jupiter.api.Assertions.*;
@DataJpaTest
class ExtensionRepositoryTest {
@PersistenceContext
EntityManager entityManager;
@Autowired
private ExtensionRepository extensionRepository;
@BeforeEach
void setUp() {
}
@Test
public void testFindByExtensionType() {
// Given
String targetExtensionType = "bat";
Extension extension1 = Extension.createExtension(ExtensionType.BAT);
entityManager.persist(extension1);
// When
Optional<Extension> foundExtension = extensionRepository.findByExtensionType(targetExtensionType);
// Then
assertTrue(foundExtension.isPresent(), "Extension not found");
Extension extension = foundExtension.get();
// 추가적인 검증을 수행하거나 로깅할 수 있습니다.
}
}
[해결 방법]
package com.extension.persistence;
import com.extension.domain.entity.Extension;
import com.extension.domain.entity.ExtensionType;
import jakarta.persistence.EntityManager;
import jakarta.persistence.PersistenceContext;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import java.util.Optional;
import static org.junit.jupiter.api.Assertions.*;
@DataJpaTest
@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)
class ExtensionRepositoryTest {
@PersistenceContext
EntityManager entityManager;
@Autowired
private ExtensionRepository extensionRepository;
@BeforeEach
void setUp() {
}
@Test
public void testFindByExtensionType() {
// Given
String targetExtensionType = "bat";
Extension extension1 = Extension.createExtension(ExtensionType.BAT);
entityManager.persist(extension1);
// When
Optional<Extension> foundExtension = extensionRepository.findByExtensionType(targetExtensionType);
// Then
assertTrue(foundExtension.isPresent(), "Extension not found");
Extension extension = foundExtension.get();
// 추가적인 검증을 수행하거나 로깅할 수 있습니다.
}
}
- @AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)
해당 애너테이션을 달아주면 된다고 친절하게 나와있다>~