Я пишу простое приложение для отдыха, используя дизайн с чистой архитектурой, ссылаясь на this
Приложение работает нормально. Но приемочный тест не работает нормально. Когда я запускаю приемочный тест, я не получаю исключения бина.
Вот структура проекта
Вот мой файл build.gradle в модуле приемочных испытаний
description = "Acceptance Tests for the BDD cycle (objective: have conversaions and demonstrate requirements)"
test {
// make gradle print the test result for each test in the build (we like to see the acceptance tests running)
testLogging {
events "passed", "skipped", "failed"
}
// set the output folder for the acceptance tests that use yatspec, and print the full path after the test execution
systemProperty "yatspec.output.dir", "build/reports/yatspec"
doLast {
println "==========================================================================================="
println "Acceptance tests output: ${project.buildDir.absolutePath}/reports/yatspec/com/span/budget"
println "==========================================================================================="
}
}
// we want to run the acceptance tests after the unit tests, to follow the testing pyramid
test.mustRunAfter(
":application:configuration:test",
":application:core:test",
":application:dataproviders:test",
":application:entrypoints:test"
)
// we must copy the h2-schema.sql script into the resources folder of this module in order for the tests
// to be able to create the in-memory database successfull when initialising the connection
task copyTestResources(type: Copy) {
println "Copying resource"
from "${project(':application:dataproviders').buildDir}/resources/main/h2-schema.sql"
into "${buildDir}/resources/test"
}
processTestResources.dependsOn copyTestResources
dependencies {
compile project(":application:configuration")
compile libs.unit_tests
compile libs.acceptance_tests
compile libs.end_to_end_test
testCompile libs.string_utils
}
Как видите, я включаю compile project(":application:configuration")
в качестве зависимостей. Внутри модуля конфигурации приложения у меня есть все конфигурации бина. См. Структуру модуля конфигурации ниже.
Когда я запускаю приложение по ./gradlew bootRun
, приложение подключается правильно. Но когда я запускаю ./gradlew test
, система выдает ошибку, сообщающую, что квалифицируемый компонент не найден.
См. След ниже.
$ ./gradlew test
> Configure project :acceptance-tests
Copying resource
> Task :compileJava NO-SOURCE
> Task :processResources NO-SOURCE
> Task :classes UP-TO-DATE
> Task :compileTestJava NO-SOURCE
> Task :processTestResources NO-SOURCE
> Task :testClasses UP-TO-DATE
> Task :test NO-SOURCE
> Task :application:core:compileJava UP-TO-DATE
> Task :application:core:processResources NO-SOURCE
> Task :application:core:classes UP-TO-DATE
> Task :application:core:jar UP-TO-DATE
> Task :application:dataproviders:compileJava UP-TO-DATE
> Task :application:dataproviders:processResources UP-TO-DATE
> Task :application:dataproviders:classes UP-TO-DATE
> Task :application:dataproviders:jar UP-TO-DATE
> Task :application:entrypoints:compileJava UP-TO-DATE
> Task :application:entrypoints:processResources NO-SOURCE
> Task :application:entrypoints:classes UP-TO-DATE
> Task :application:entrypoints:jar UP-TO-DATE
> Task :application:configuration:compileJava UP-TO-DATE
> Task :application:configuration:processResources UP-TO-DATE
> Task :application:configuration:classes UP-TO-DATE
> Task :application:configuration:compileTestJava NO-SOURCE
> Task :application:configuration:processTestResources NO-SOURCE
> Task :application:configuration:testClasses UP-TO-DATE
> Task :application:configuration:test NO-SOURCE
> Task :application:core:compileTestJava UP-TO-DATE
> Task :application:core:processTestResources NO-SOURCE
> Task :application:core:testClasses UP-TO-DATE
> Task :application:core:test UP-TO-DATE
> Task :application:dataproviders:compileTestJava UP-TO-DATE
> Task :application:dataproviders:processTestResources NO-SOURCE
> Task :application:dataproviders:testClasses UP-TO-DATE
> Task :application:dataproviders:test UP-TO-DATE
> Task :application:entrypoints:compileTestJava UP-TO-DATE
> Task :application:entrypoints:processTestResources NO-SOURCE
> Task :application:entrypoints:testClasses UP-TO-DATE
> Task :application:entrypoints:test UP-TO-DATE
> Task :application:configuration:jar SKIPPED
> Task :acceptance-tests:compileJava UP-TO-DATE
> Task :acceptance-tests:processResources NO-SOURCE
> Task :acceptance-tests:classes UP-TO-DATE
> Task :acceptance-tests:compileTestJava
> Task :acceptance-tests:copyTestResources UP-TO-DATE
> Task :acceptance-tests:processTestResources NO-SOURCE
> Task :acceptance-tests:testClasses
> Task :acceptance-tests:test
com.span.budget.endtoend.transaction.getdetails.TransactionDetailsEndToEndTest > returnWelcomeMessage FAILED
org.springframework.beans.factory.UnsatisfiedDependencyException
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException
com.span.budget.endtoend.transaction.getdetails.TransactionDetailsEndToEndTest > returnTheDetailsOfTheTransaction FAILED
org.springframework.beans.factory.UnsatisfiedDependencyException
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException
com.span.budget.businessrequirements.transaction.getdetails.GetTransactionDetailsAcceptanceTest > returnTheDetailsOfTheTransaction PASSED
2019-03-27 05:47:48.649 INFO 6536 --- [ Thread-5] ationConfigEmbeddedWebApplicationContext : Closing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@3b21fe3b: startup date [Wed Mar 27 05:47:41 SGT 2019]; root of context hierarchy
2019-03-27 05:47:48.681 INFO 6536 --- [ Thread-5] o.s.j.d.e.EmbeddedDatabaseFactory : Shutting down embedded database: url='jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=false'
3 tests completed, 2 failed
> Task :acceptance-tests:test FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':acceptance-tests:test'.
> There were failing tests. See the report at: file:///C:/Rajesh/workspace/budget/acceptance-tests/build/reports/tests/test/index.html
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 13s
19 actionable tasks: 2 executed, 17 up-to-date
Что я здесь не так делаю? Какие-либо предложения.
Вы можете найти полный код здесь