2

As we know, we can use backticks to declare a method name contains special characters, such as space, which sounds like a good way to say a unit test name. For example, we could declare a test case like this

class SampleTest {    
    @Test
    def `it should return a space` {
      ....  
    }
}

When I run this test case, I supposed to get the result

[info] Test run started
[info] Test SampleTest.it$u0020should$u0020return$u0020a$u0020space started
[info] Test run finished: 0 failed, 0 ignored, 1 total, 0.538s
[info] ScalaTest

All spaces display as $u0020. Is there any way to show spaces literally with JUnit test style?

[info] Test SampleTest.it should return a space started

I can't use Scala Spec test because I have to use JMockit in our test code.

JUnit reflects the method name it should return a space as it$u0020should$u0020return$u0020a$u0020space

Yanbin
  • 124
  • 7
  • Not sure if that is what you want or if it would work, but you might be able to achieve that with a [custom sbt logger](http://www.scala-sbt.org/0.12.4/docs/Howto/logging.html#custom) if you are using sbt, that is. – Sascha Kolberg Aug 31 '15 at 17:43
  • 1
    That's not JUnit that reflect "special characters" as unicode preceded by `$u`, it's scalac. If I am not mistaken Scala's reflection API has a method to encode/decode these. – pedrofurla Aug 31 '15 at 22:56

2 Answers2

1

It seems to me that the safest bet here would be checking if you can hook into the test reporter or open an issue at the ScalaTest repository asking to print the "decoded" name instead of the "encoded" name.

The name you see is how scalac encodes names in java byte code. Printing it straight back could probably be considered a minor bug in ScalaTest.

Doesn't look like you'd be in luck with trying to replace sbt's logger. Jsureth from the sbt team seems to indicate that you can't replace sbt's existing logger, but only add additional ones. Source: https://gitter.im/sbt/sbt?at=55c7ec838f067d637598ae9f

cvogt
  • 11,260
  • 30
  • 46
0

I have answered my question in this question https://stackoverflow.com/a/37084254/197741.

Look at https://github.com/sbt/junit-interface

-s Try to decode Scala names in stack traces and test names. Fall back silently to non-decoded names if no matching Scala library is on the class path.

So we can say

testOptions += Tests.Argument(TestFrameworks.JUnit, "-q", "-v", "-s")

in build.sbt file, then for a method

def `get one hundred if fifty plus fifty started` {}

the test result shows

[info] Test ScalaTest.get one hundred if fifty plus fifty started

not

[info] Test ScalaTest.get$u0020one$u0020hundred$u0020if$u0020fifty$u0020plus$u0020fifty started
Community
  • 1
  • 1
Yanbin
  • 124
  • 7