我正在通过引用this
使用干净的架构设计来编写简单的REST服务应用程序应用程序运行正常。但是验收测试运行不正常。当我运行验收测试时,没有任何异常。
这是项目结构
这是我的验收测试模块中的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")
作为依赖项。在应用程序配置模块内部,我具有所有Bean配置。请参阅下面的配置模块结构。
当我通过./gradlew bootRun
运行该应用程序时,该应用程序已正确连接。但是当我运行./gradlew test
时,系统抛出错误,提示未找到合格的bean。
请参阅下面的跟踪。
$ ./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
我在这里做错了什么?有什么建议么。 您可以找到完整的代码here