我有一个多模块Sbt项目。在此项目中,我使用ScalaTest,并且希望在保留控制台输出的同时生成Html和Xml报告。
我在一个简单的项目上关注了本文,一切都很好:https://blog.ssanj.net/posts/2016-07-06-write-html-test-reports-with-scalatest-while-retaining-console-output.html
但是在我的多模块项目中,testOptions
似乎被忽略了。这些设置是在通用设置定义中定义的,可以在所有模块中重复使用:
def settingsCommon: Seq[Setting[_]] = Seq(
scalaVersion := DefaultScalaVersion,
scalacOptions ++= Seq(
"-feature",
"-encoding", "utf8",
...
),
testOptions in Test ++= Seq(
Tests.Argument(TestFrameworks.ScalaTest, "-oDI"),
Tests.Argument(TestFrameworks.ScalaTest, "-h", "target/test-reports"),
Tests.Argument(TestFrameworks.ScalaTest, "-u", "target/test-reports")
),
...
)
lazy val root = (project in file("."))
.settings(settingsCommon)
.aggregate(
`shared`,
`module-1`
)
lazy val `shared` = (project in file("shared"))
.settings(
name := "shared"
)
.settings(settingsCommon)
lazy val `module-1` = (project in file("module-1"))
.settings(settingsCommon)
.dependsOn(`shared`)
检查 testOptions 会得到以下结果(看起来还可以):
sbt:my-project> inspect testOptions
[info] Task: scala.collection.Seq[sbt.TestOption]
[info] Description:
[info] Options for running tests.
[info] Provided by:
[info] ProjectRef(uri("file:/home/me/my-project/"), "root") / Test / testOptions
[info] Defined at:
[info] /home/me/my-project/build.sbt:43
[info] Reverse dependencies:
[info] Test / test / testOptions
[info] Test / testQuick / testOptions
[info] Test / testOnly / testOptions
[info] Delegates:
[info] Test / testOptions
[info] Runtime / testOptions
[info] Compile / testOptions
[info] testOptions
[info] ThisBuild / Test / testOptions
[info] ThisBuild / Runtime / testOptions
[info] ThisBuild / Compile / testOptions
[info] ThisBuild / testOptions
[info] Zero / Test / testOptions
[info] Zero / Runtime / testOptions
[info] Zero / Compile / testOptions
[info] Global / testOptions
[info] Related:
[info] shared / Test / test / testOptions
[info] module-1 / Test / testOptions
[info] module-1 / Test / testOnly / testOptions
[info] ...
({/home/me/my-project/build.sbt:43
是定义选项的正确行号)
添加修改: 显示测试选项看起来也不错:
sbt:my-project> ;reload;show testOptions
[info] Loading global plugins from /home/me/.sbt/1.0/plugins
[info] Loading settings for project backend-build from git.sbt,plugins.sbt ...
[info] Loading project definition from /home/me/my-project/project
[info] Loading settings for project root from build.sbt ...
[info] Resolving key references (26112 settings) ...
[info] Set current project to my-project (in build file:/home/me/my-project/)
[info] shared / Test / testOptions
[info] List(Argument(Some(TestFramework(org.scalatest.tools.Framework, org.scalatest.tools.ScalaTestFramework)),List(-oDI)), Argument(Some(TestFramework(org.scalatest.tools.Framework, org.scalatest.tools.ScalaTestFramework)),List(-h, target/test-reports)), Argument(Some(TestFramework(org.scalatest.tools.Framework, org.scalatest.tools.ScalaTestFramework)),List(-u, target/test-reports)))
... The same for each modules ...
... Except one that is a Playframework module:
[info] play-module / Test / testOptions
[info] List(Argument(Some(TestFramework(org.specs2.runner.Specs2Framework, org.specs2.runner.SpecsFramework)),List(sequential, true, junitxml, console)), Argument(Some(TestFramework(com.novocode.junit.JUnitFramework)),List(--ignore-runners=org.specs2.runner.JUnitRunner)), Argument(Some(TestFramework(org.scalatest.tools.Framework, org.scalatest.tools.ScalaTestFramework)),List(-oDI)), Argument(Some(TestFramework(org.scalatest.tools.Framework, org.scalatest.tools.ScalaTestFramework)),List(-h, target/test-reports)), Argument(Some(TestFramework(org.scalatest.tools.Framework, org.scalatest.tools.ScalaTestFramework)),List(-u, target/test-reports)))
修改2:
并且show testFrameworks
显示ScalaTest等:
[info] List(TestFramework(org.scalacheck.ScalaCheckFramework), TestFramework(org.specs2.runner.Specs2Framework, org.specs2.runner.SpecsFramework), TestFramework(org.specs.runner.SpecsFramework), TestFramework(org.scalatest.tools.Framework, org.scalatest.tools.ScalaTestFramework), TestFramework(com.novocode.junit.JUnitFramework))
尽管使用此配置,但我没有HTML报告,只有默认的XML报告,“-oDI”参数无效。
您能帮我解决这个问题吗?谢谢