我们目前正在使用SBT和Play来完成一个项目。
我们希望启动数据库并仅播放 ONCE 以降低测试时间。
SBT提供Tests.Setup
和Tests.Cleanup
来执行此操作; http://www.scala-sbt.org/0.12.4/docs/Detailed-Topics/Testing.html
我在test/util/TestServer.scala
object TestServer {
def start = println("hello")
}
为了让这个打印我把它挂在SBT配置中:
play.Project(name = appName, applicationVersion = appVersion, dependencies = appDependencies)
.settings(
// snip .. wiring resolvers and template/routes imports here
testOptions in Test += Tests.Argument("junitxml", "console"),
testOptions in Test += Tests.Setup(_.loadClass("util.TestServer$").getMethod("start").invoke(null)),
testOptions in Test += Tests.Cleanup(_.loadClass("util.TestServer$").getMethod("stop").invoke(null)),
scalacOptions += "-feature",
doc in Compile
However when I run this, it complains about not finding the the TestServer class:
$ sh play.sh test
[info] Loading project definition from /Users/markdejong/Projects/malmberg-baps/project
[info] Set current project to Malmberg (in build file:/Users/markdejong/Projects/malmberg-baps/)
[info] Updating {file:/Users/markdejong/Projects/malmberg-baps/}core...
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Done updating.
[info] Updating {file:/Users/markdejong/Projects/malmberg-baps/}macros...
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Passed: Total 0, Failed 0, Errors 0, Passed 0
[info] No tests to run for core/test:test
[info] Done updating.
[info] Updating {file:/Users/markdejong/Projects/malmberg-baps/}Malmberg...
[info] Resolving org.apache.httpcomponents#httpclient;4.2 ...
[info] Passed: Total 0, Failed 0, Errors 0, Passed 0
[info] No tests to run for macros/test:test
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Done updating.
java.lang.ClassNotFoundException: util.TestServer$
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at ApplicationBuild$$anonfun$6$$anonfun$apply$10.apply(Build.scala:89)
at ApplicationBuild$$anonfun$6$$anonfun$apply$10.apply(Build.scala:89)
at sbt.ForkTests$$anonfun$sbt$ForkTests$$all$1$1.apply(ForkTests.scala:20)
at sbt.ForkTests$$anonfun$sbt$ForkTests$$all$1$1.apply(ForkTests.scala:20)
at sbt.std.TaskExtra$$anon$1$$anonfun$fork$1$$anonfun$apply$1.apply(TaskExtra.scala:99)
at sbt.std.Transform$$anon$3$$anonfun$apply$2.apply(System.scala:45)
at sbt.std.Transform$$anon$3$$anonfun$apply$2.apply(System.scala:45)
at sbt.std.Transform$$anon$4.work(System.scala:64)
at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:237)
at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:237)
at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:18)
at sbt.Execute.work(Execute.scala:244)
at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:237)
at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:237)
at sbt.ConcurrentRestrictions$$anon$4$$anonfun$1.apply(ConcurrentRestrictions.scala:160)
at sbt.CompletionService$$anon$2.call(CompletionService.scala:30)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
[error] (Malmberg/test:executeTests) java.lang.ClassNotFoundException: util.TestServer$
[error] Total time: 11 s, completed Apr 23, 2014 7:11:07 PM
What is the problem here?
$ sh play.sh test
[info] Loading project definition from /Users/markdejong/Projects/malmberg-baps/project
[info] Set current project to Malmberg (in build file:/Users/markdejong/Projects/malmberg-baps/)
[info] Updating {file:/Users/markdejong/Projects/malmberg-baps/}core...
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Done updating.
[info] Updating {file:/Users/markdejong/Projects/malmberg-baps/}macros...
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Passed: Total 0, Failed 0, Errors 0, Passed 0
[info] No tests to run for core/test:test
[info] Done updating.
[info] Updating {file:/Users/markdejong/Projects/malmberg-baps/}Malmberg...
[info] Resolving org.apache.httpcomponents#httpclient;4.2 ...
[info] Passed: Total 0, Failed 0, Errors 0, Passed 0
[info] No tests to run for macros/test:test
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Done updating.
java.lang.ClassNotFoundException: util.TestServer$
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at ApplicationBuild$$anonfun$6$$anonfun$apply$10.apply(Build.scala:89)
at ApplicationBuild$$anonfun$6$$anonfun$apply$10.apply(Build.scala:89)
at sbt.ForkTests$$anonfun$sbt$ForkTests$$all$1$1.apply(ForkTests.scala:20)
at sbt.ForkTests$$anonfun$sbt$ForkTests$$all$1$1.apply(ForkTests.scala:20)
at sbt.std.TaskExtra$$anon$1$$anonfun$fork$1$$anonfun$apply$1.apply(TaskExtra.scala:99)
at sbt.std.Transform$$anon$3$$anonfun$apply$2.apply(System.scala:45)
at sbt.std.Transform$$anon$3$$anonfun$apply$2.apply(System.scala:45)
at sbt.std.Transform$$anon$4.work(System.scala:64)
at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:237)
at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:237)
at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:18)
at sbt.Execute.work(Execute.scala:244)
at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:237)
at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:237)
at sbt.ConcurrentRestrictions$$anon$4$$anonfun$1.apply(ConcurrentRestrictions.scala:160)
at sbt.CompletionService$$anon$2.call(CompletionService.scala:30)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
[error] (Malmberg/test:executeTests) java.lang.ClassNotFoundException: util.TestServer$
[error] Total time: 11 s, completed Apr 23, 2014 7:11:07 PM
,但同样的错误。
使用sbt版本0.13.0和Play 2.2.2
答案 0 :(得分:1)
感谢吉田健二我发现了这个问题。
这确实是Play Framework引入的“fork”模式。您必须将其设置为false才能使其适用于这些版本。