Our TDML test scala runner JUnit tests often look like this:

@Test def test_someVariantOfTheTDMLTestCaseName() : Unit = {
runner.runOneTest("theExactTDMLTestName") }

This has always bugged me. We don't need the freedom for the method name
and the test name to differ.
It would be great if the test name was exactly the test method name
automatically.

Voila:

/* Uses sourcecode library (https://github.com/com-lihaoyi/sourcecode) to
capture method name
 * and use it as the test name.
 * @param methodName implicitly computed name of method calling this method.
 */
def doTest(implicit methodName: sourcecode.Enclosing): Unit =
  runner.runOneTest(methodName.value.split("#").last)

@Test def theExactTDMLTestName() = doTest

// The test name must be exactly the method name letter for letter, hence
test names
// must be suitable for use as scala/java identifiers, so no hyphens or
periods allowed.

This sourcecode library is super cool. Has the ability to get the file
name, line number, enclosing class, enclosing definition, whether it is
val, lazy val, or def, etc.
It's all pretty easy to use.

- Mike Beckerle

Reply via email to