How to get the name of the current scalajs / uTest test case

124 views Asked by At

How can I get the name of the currently running uTest test case?

During the test case I usually use println(...) or log.debug(...) to print and check various values. At the beginning of the test case I print the name of the test case.

I can always do this:

object MyTests extends TestSuite

  def tests = TestSuite {

    "MyTest01" - {

      println("MyTest01 starting ***************************************************")

      val x = Thing.doComplexCalc
      println("x = " + x )

      val y = AnotherThing.doSomethingMore( x )
      println("y = " + y )
      assert(y=="mysterious output")
    }
  }
}

In this (extremely simplified) example "MyTest01" is duplicated. What I'm looking for is a way to remove the duplication, e.g. like this:

object MyTests extends TestSuite

  def tests = TestSuite {

    "MyTest01" - {

      println(getTest().name + " starting ***************************************************")

      val x = Thing.doComplexCalc
      println("x = " + x )

      val y = AnotherThing.doSomethingMore( x )
      println("y = " + y )
      assert(y=="mysterious output")
    }
  }
}

Test name is available from tests.toSeq().name but how to know what case is running especially if they are run parallel using sbt.

2

There are 2 answers

3
Li Haoyi On BEST ANSWER

It's not available right now. There's an open issue to make it so

https://github.com/lihaoyi/utest/issues/71

3
Richard Gomes On
import utest._
...
val name = implicitly[utest.framework.TestPath].value