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;

有什么诀窍可以让它起作用吗?

推荐答案

函数名中对空格的支持已经达到added,现在可以在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.

Kotlin相关问答推荐

用浮点数或十进制数给出错误答案的阶乘计算

查看流数据和改进的HTTP请求的模型

导入org.gradle.jvm.toolchain.internal.JavaToolchainFactory未解析引用:Java工具链工厂

在KMM合成多平台中创建特定于平台的视图

解决Microronaut中多个可能的Bean候选者冲突

使用另一个对象的列表创建对象

为什么记得不将 StateFlow 转换为特定类型?

如何从kotlin中的ArrayList中删除所有元素

将 Gradle 子元素与 Kotlin 多平台一起使用

变量后的Android问号

Kotlin:找不到符号类片段或其他 android 类

Kotlin 具体化的泛型不会按计划保持类型

将协同路由调用放在存储库或ViewModel中哪个更好?

使用 Paging 3 时保存并保留 LazyColumn 滚动位置

有没有办法在数据类构建时转换属性的值?

launch 仅从 Kotlin 1.3 开始可用,不能在 Kotlin 1.2 中使用

无法解决:androidx.lifecycle:lifecycle-extensions-ktx:2.0.0-alpha1

Kotlin 中内部可见性修饰符的范围

有没有办法在Kotlin中设置一个私有常量

为什么 Kotlin 会收到这样的 UndeclaredThrowableException 而不是 ParseException?