Я использую базу данных PostgreSQL, платформу Spock для тестов и Maven в качестве системы сборки.
Я прочитал довольно много сообщений в блоге, но, кажется, все настраивают эту настройку по-своему.
Я действительно сбит с толку, так как думал, что это будет довольно простая задача.
У меня сейчас есть эта конфигурация:
Код: Выделить всё
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.test.context.DynamicPropertyRegistry
import org.springframework.test.context.DynamicPropertySource
import org.testcontainers.containers.PostgreSQLContainer
import org.testcontainers.spock.Testcontainers
import org.testcontainers.utility.DockerImageName
import spock.lang.Shared
import spock.lang.Specification
@SpringBootTest
@Testcontainers
class TransactionRepositoryTest extends Specification {
private static final String POSTGRES_IMAGE = "postgres:latest"
private static final String POSTGRES_DB = "assignment-test"
private static final String POSTGRES_USER = "postgres"
private static final String POSTGRES_PASSWORD = "postgrespass"
@Shared
static PostgreSQLContainer postgresql = new PostgreSQLContainer(DockerImageName.parse(POSTGRES_IMAGE))
.withDatabaseName(POSTGRES_DB)
.withUsername(POSTGRES_USER)
.withPassword(POSTGRES_PASSWORD)
@DynamicPropertySource
static void registerPgProperties(DynamicPropertyRegistry registry) {
registry.add("spring.datasource.url", postgresql::getJdbcUrl)
registry.add("spring.datasource.username", postgresql::getUsername)
registry.add("spring.datasource.password", postgresql::getPassword)
}
// some tests
}
(докер запущен)
Код: Выделить всё
java.lang.IllegalStateException: Failed to load ApplicationContext for [WebMergedContextConfiguration@4f59a516 testClass = com.transactionsassignment.integration.transaction.TransactionRepositoryTest, locations = [], classes = [com.transactionsassignment.TransactionsAssignmentApplication], contextInitializerClasses = [], activeProfiles = [], propertySourceLocations = [], propertySourceProperties = ["org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true", "server.port=0"], contextCustomizers = [org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@3e84448c, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@7e5afaa6, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.web.client.TestRestTemplateContextCustomizer@73e22a3d, org.springframework.boot.test.autoconfigure.actuate.observability.ObservabilityContextCustomizerFactory$DisableObservabilityContextCustomizer@1f, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@0, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizerFactory$Customizer@306e95ec, org.springframework.test.context.support.DynamicPropertiesContextCustomizer@66ed20ff, org.spockframework.spring.mock.SpockContextCustomizer@0, org.springframework.boot.test.context.SpringBootTestAnnotation@19902e80], resourceBasePath = "src/main/webapp", contextLoader = org.springframework.boot.test.context.SpringBootContextLoader, p a r e n t = n u l l ] < b r / > < b r / > a t o r g . s p r i n g f r a m e w o r k . t e s t . c o n t e x t . c a c h e . D e f a u l t C a c h e A w a r e C o n t e x t L o a d e r D e l e g a t e . l o a d C o n t e x t ( D e f a u l t C a c h e A w a r e C o n t e x t L o a d e r D e l e g a t e . j a v a : 1 4 2 ) < b r / > a t o r g . s p r i n g f r a m e w o r k . t e s t . c o n t e x t . s u p p o r t . D e f a u l t T e s t C o n t e x t . g e t A p p l i c a t i o n C o n t e x t ( D e f a u l t T e s t C o n t e x t . j a v a : 1 2 7 ) < b r / > a t o r g . s p r i n g f r a m e w o r k . t e s t . c o n t e x t . s u p p o r t . D e p e n d e n c y I n j e c t i o n T e s t E x e c u t i o n L i s t e n e r . i n j e c t D e p e n d e n c i e s ( D e p e n d e n c y I n j e c t i o n T e s t E x e c u t i o n L i s t e n e r . j a v a : 1 4 1 ) < b r / > a t o r g . s p r i n g f r a m e w o r k . t e s t . c o n t e x t . s u p p o r t . D e p e n d e n c y I n j e c t i o n T e s t E x e c u t i o n L i s t e n e r . p r e p a r e T e s t I n s t a n c e ( D e p e n d e n c y I n j e c t i o n T e s t E x e c u t i o n L i s t e n e r . j a v a : 9 7 ) < b r / > a t o r g . s p r i n g f r a m e w o r k . t e s t . c o n t e x t . T e s t C o n t e x t M a n a g e r . p r e p a r e T e s t I n s t a n c e ( T e s t C o n t e x t M a n a g e r . j a v a : 2 4 1 ) < b r / > a t o r g . s p o c k f r a m e w o r k . s p r i n g . S p r i n g T e s t C o n t e x t M a n a g e r . p r e p a r e T e s t I n s t a n c e ( S p r i n g T e s t C o n t e x t M a n a g e r . j a v a : 5 6 ) < b r / > a t o r g . s p o c k f r a m e w o r k . s p r i n g . S p r i n g I n t e r c e p t o r . i n t e r c e p t I n i t i a l i z e r M e t h o d ( S p r i n g I n t e r c e p t o r . j a v a : 4 6 ) < b r / > a t o r g . s p o c k f r a m e w o r k . r u n t i m e . e x t e n s i o n . A b s t r actMethodInterceptor.intercept(AbstractMethodInterceptor.java:24)
at org.spockframework.runtime.extension.MethodInvocation.proceed(MethodInvocation.java:101)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$prepare$2(NodeTestTask.java:123)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.prepare(NodeTestTask.java:123)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:90)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
at org.spockframework.runtime.model.MethodInfo.invoke(MethodInfo.java:156)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:35)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:54)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:147)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:127)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:90)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.lambda$execute$0(EngineExecutionOrchestrator.java:55)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.withInterceptedStreams(EngineExecutionOrchestrator.java:102)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:54)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:114)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:86)
at org.junit.platform.launcher.core.DefaultLauncherSession$DelegatingLauncher.execute(DefaultLauncherSession.java:86)
at org.junit.platform.launcher.core.SessionPerRequestLauncher.execute(SessionPerRequestLauncher.java:53)
at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:57)
at com.intellij.rt.junit.IdeaTestRunner$Repeater$1.execute(IdeaTestRunner.java:38)
at com.intellij.rt.execution.junit.TestsRepeater.repeat(TestsRepeater.java:11)
at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:35)
at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:232)
at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:55)
Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to process import candidates for configuration class [com.transactionsassignment.TransactionsAssignmentApplication]: E r r o r p r o c e s s i n g c o n d i t i o n o n o r g . s p r i n g f r a m e w o r k . b o o t . a u t o c o n f i g u r e . j d b c . D a t a S o u r c e A u t o C o n f i g u r a t i o n $ E m b e d d e d D a t a b a s e C o n f i g u r a t i o n < b r / > < b r / > < / c o d e > < b r / > Э т о м о й з н а т о к : < / p > < b r / > < p r e c l a s s = " l a n g - x m l P r e t t y p r i n t - o v e r r i d e " > < c o d e > & l t ; p r o p e r t i e s & g t ; < b r / > & l t ; j a v a . v e r s i o n & g t ; 1 7 & l t ; / j a v a . v e r s i o n & g t ; < b r / > & l t ; m a v e n . v e r s i o n & g t ; 3 . 1 . 0 & l t ; / m a v e n . v e r s i o n & g t ; < b r / > & l t ; o r g . m a p s t r u c t . v e r s i o n & g t ; 1 . 5 . 5 . F i n a l & l t ; / o r g . m a p s t r u c t . v e r s i o n & g t ; < b r / > & l t ; p o s t g r e s q l . v e r s i o n & g t ; 4 2 . 6 . 0 & l t ; / p o s t g r e s q l . v e r s i o n & g t ; < b r / > 3.0.0
4.0.12
1.18.3
2.4-M1-groovy-4.0
org.springframework.boot
spring-boot-starter-data-jpa
org.springframework.boot
spring-boot-starter-data-rest
org.springframework.boot
spring-boot-starter-web
org.mapstruct
mapstruct
${org.mapstruct.version}
org.postgresql
postgresql
runtime
${postgresql.version}
org.springframework.boot
spring-boot-starter-test
test
org.apache.groovy
groovy
${groovy.version}
org.spockframework
spock-core
${spock.version}
test
org.spockframework
spock-spring
${spock.version}
test
org.testcontainers
testcontainers
${testcontainers.version}
test
org.testcontainers
junit-jupiter
${testcontainers.version}
test
org.testcontainers
postgresql
${testcontainers.version}
test
org.testcontainers
spock
${testcontainers.version}
test
org.apache.maven.plugins
maven-compiler-plugin
3.11.0
${java.version}
${java.version}
org.mapstruct
mapstruct-processor
${org.mapstruct.version}
org.codehaus.gmavenplus
gmavenplus-plugin
${gmavenplus.version}
compileTests
maven-surefire-plugin
${maven.version}
false
**/*Spec.java
**/*Test.java
Пожалуйста, помогите мне избавиться от этой ошибки и правильно настроить эту конфигурацию.>
Подробнее здесь: https://stackoverflow.com/questions/763 ... -and-spock
Мобильная версия