When compiling following code snippet:
class MyTest {
@org.junit.Test
def `test test`() {
}
}
Method test test
is being put to bytecode as test$u0020test
.
Why it happens and how can this be disabled?
Space is valid identifier for method name according to JVM spec. Also, there is no mention of such encoding in Scala language specification. Moreover, other JVM languages like Groovy and Groovy-based Spock Framework do not encode spaces.
Why do i need this: Human-friendly JUnit test names and test reports.
Java 1.8.0_45, Scala 2.11.6
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
It wouldn't be callable from Java otherwise. Interoperability with Java was an important consideration in the design of Scala.
OTOH, experience has shown that it's best to just stick to Java names in such cases.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With