jeudi 28 janvier 2016

How to add 'testListener' to custom test reporter in SBT

I'm having difficulty implementing a custom test reporter in Scala using SBT.

I have a basic SBT project set up with this build.sbt file:

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 += ??? // This line does not compile

My MyTest.scala class is located in the projectsfolder under projects/custom/framework/MyTest.scala and looks like this:

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")
    }
}

The documentation here is sparse, and i'm obviously missing something. It states that i need to

Specify the test reporters you want to use by overriding the testListeners method in your project definition. Where customTestListener is of type sbt.TestReportListener.

This should be possible by doing testListeners += customTestListener. Since my class MyTest extends TestReportListener i thought i could just do testListeners += custom.framework.MyTest or testListeners += new custom.framework.MyTest, but this clearly is not the case.

I'm running sbt test to execute the tests.

Does anyone know how this is done correctly?

Aucun commentaire:

Enregistrer un commentaire