【问题标题】:How to add 'testListener' to custom test reporter in SBT如何在 SBT 中将“testListener”添加到自定义测试报告器
【发布时间】:2016-05-05 23:55:42
【问题描述】:

我在实现 custom test reporter in Scala using SBT 时遇到了困难。

我用这个 build.sbt 文件设置了一个基本的 SBT 项目:

name := "Test Framework"

version := "0.1"
scalaVersion := "2.11.7"

scalacOptions += "-deprecation"
scalacOptions += "-feature"

libraryDependencies += "org.scalatest" % "scalatest_2.11" % "2.2.4" % "test"
libraryDependencies += "org.scalacheck" %% "scalacheck" % "1.12.4" % "test"


testFrameworks += new TestFramework("custom.framework.MyTest")
testListeners += new MyTest()

我的MyTest.scala 类位于projects/custom/framework/MyTest.scala 下的projects文件夹中,如下所示:

import sbt.TestsListener._
import sbt.TestReportListener._

class MyTest extends TestReportListener {

    def doInit(): Unit = {
        println("Starting Test")
    }

    def testEvent(event: TestEvent): Unit = {
        println(event.result.get)
    }

    def startGroup(name: String): Unit = {
        println("Group Started")
    }
}

这里的文档很少,我显然遗漏了一些东西。它指出我需要

通过覆盖项目定义中的 testListeners 设置来指定要使用的测试报告器。其中 customTestListener 的类型为 sbt.TestReportListener。

这应该可以通过testListeners += customTestListener 来实现。 因为我的class MyTest extends TestReportListener 我以为我可以做testListeners += custom.framework.MyTest 或testListeners += new custom.framework.MyTest,但显然不是这样。

我正在运行sbt test 来执行测试,输出是

error: not found: value custom
testListeners += new custom.framework.MyTest

我不确定这应该如何工作。 有谁知道这是如何正确完成的?

【问题讨论】:

    标签: scala testing sbt


    【解决方案1】:

    我不明白为什么说明包不起作用,但将MyTest.scala 文件移到project 目录,并删除custom.frameworkpackage 使它起作用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-18
      • 1970-01-01
      • 2019-11-13
      • 1970-01-01
      相关资源
      最近更新 更多