Search code examples
scalaunit-testingscala.jsutest

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


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.


Solution

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

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