In my unit tests I use Kotlin's backticked methods for better readability, e.g.
@Test fun `Foo should return bar`()
It works nice and well for tests in <module>/src/test
directory, but when I try to do the same in <module>/src/androidTest
I get an exception:
Error:java.lang.IllegalArgumentException: bad descriptor: Lcom/packageName/MainActivityTest$Foo should return bar$1;
Error:Execution failed for task ':sample:transformClassesWithDexBuilderForDebugAndroidTest'. > com.android.build.api.transform.TransformException: org.gradle.tooling.BuildException: com.android.dx.cf.iface.ParseException: bad descriptor: Lcom/packageName/MainActivityTest$Foo should return bar$1;
Is there some trick to make it work?
As @nhaarman mentioned, Android does not support backticked function names. From the Kotlin Coding Conventions:
In tests (and only in tests), it's acceptable to use method names with spaces enclosed in backticks. (Note that such method names are currently not supported by the Android runtime.) Underscores in method names are also allowed in test code.
class MyTestCase { @Test fun `ensure everything works`() { ... } @Test fun ensureEverythingWorks_onAndroid() { ... } }
Support for spaces in function names has been added and is now available in API 30.
To use it, set buildToolsVersion
, compileSdkVersion
and targetSdkVersion
to 30+ and run your tests on an Android 30+ device. If you want to use this in anything else than tests, you'll have to set minSdkVersion
to 30+ as well.
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