我玩了!项目,我想添加一些代码覆盖率信息.到目前为止,我已经尝试过JaCoCo和scct.前者存在基于字节码的问题,因此它似乎对Scala编译器自动生成的方法(例如copy或)的缺失测试发出警告canEqual.scct似乎是一个更好的选择,但无论如何我在两个测试期间都会遇到很多错误.
让我坚持使用scct.我基本上每次尝试连接数据库的测试都会出错.我的许多测试都将一些灯具加载到内存中的H2数据库中,然后进行一些断言.我的Global.scala包含
override def onStart(app: Application) {
SessionFactory.concreteFactory = Some(() => connection)
def connection() = {
Session.create(DB.getConnection()(app), new MySQLInnoDBAdapter)
}
}
Run Code Online (Sandbox Code Playgroud)
而测试通常被封闭在一个块中
class MySpec extends Specification {
def app = FakeApplication(additionalConfiguration = inMemoryDatabase())
"The models" should {
"be five" in running(app) {
Fixtures.load()
MyModels.all.size should be_==(5)
}
}
}
Run Code Online (Sandbox Code Playgroud)
该行running(app)允许我在连接到内存数据库的工作应用程序的上下文中运行测试,至少通常是这样.但是当我运行代码覆盖任务(例如scct)时coverage:doc,我会收到很多与连接数据库相关的错误.
更奇怪的是,至少有4种不同的错误,例如:
为什么在默认配置中启动测试能够连接到数据库,而在scct(或JaCoCo)的上下文中运行无法初始化缓存和数据库?
scala是版本2.10.2,sbt是0.13.0
我正在尝试为scala单元测试代码覆盖设置scct,所以在build.sbt中我添加了
seq(ScctPlugin.instrumentSettings : _*)
Run Code Online (Sandbox Code Playgroud)
在project/plugins.sbt中我添加了
resolvers += Classpaths.typesafeResolver
resolvers += "scct-github-repository" at "http://mtkopone.github.com/scct/maven-repo"
addSbtPlugin("reaktor" %% "sbt-scct" % "0.2-SNAPSHOT")
Run Code Online (Sandbox Code Playgroud)
我得到像......一样的错误
module not found: reaktor#sbt-scct;0.2-SNAPSHOT
Run Code Online (Sandbox Code Playgroud)
最后的消息是
[warn] ==== scct-github-repository: tried
[warn] http://mtkopone.github.com/scct/maven-repo/reaktor/sbt-scct_2.10_0.13/0.2-SNAPSHOT/sbt-scct-0.2-SNAPSHOT.pom
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: UNRESOLVED DEPENDENCIES ::
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: reaktor#sbt-scct;0.2-SNAPSHOT: not found
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn]
[warn] Note: Some unresolved dependencies have extra attributes. Check that these dependencies exist with the requested attributes.
[warn] reaktor:sbt-scct:0.2-SNAPSHOT (sbtVersion=0.13, scalaVersion=2.10)
Run Code Online (Sandbox Code Playgroud)
我看在http://mtkopone.github.io/scct/maven-repo/reaktor/ ,我看到了一个我似乎需要缺少如我看到
sbt-scct_2.9.2_0.13/
scct_2.10/
and a …Run Code Online (Sandbox Code Playgroud)