1

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.

user4955663
  • 1,039
  • 2
  • 13
  • 21

2 Answers2

1
import utest._
...
val name = implicitly[utest.framework.TestPath].value
Richard Gomes
  • 5,675
  • 2
  • 44
  • 50
  • 2
    While this code snippet may answer the question, explaining *how* it answers the question will ensure that it remains valuable for future visitors. – miken32 Apr 23 '18 at 18:24
  • @miken32 : The question asks how to obtain the name of a certain test case. The snippet is pretty clear and provides a direct, concise and precise answer to the question. By the way, I even provide the import statement, something people rarely provides. – Richard Gomes Apr 23 '18 at 18:44
  • @RichardGomes, the code snippet looks fine. But don't assume that code speaks for itself! What is needed is a brief contextual response to the question; describe succinctly what the code example does, in a way that responds to the specifics of the question. It doesn't need to be long; but it does need to be an answer :-) – bignose Apr 24 '18 at 01:07
0

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

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

Li Haoyi
  • 15,330
  • 17
  • 80
  • 137