7

我有以下测试,其中测试名称带有空格和反引号用于我的仪器测试

@RunWith(AndroidJUnit4::class)
class MyTestClass {
    @Rule
    @JvmField
    var activityRule: ActivityTestRule<MainActivity> = ActivityTestRule(MainActivity::class.java)

    @Test
    fun `My space name testing`() {
          // Some test
    }
}

但是运行时却无法执行(即没有找到测试)

检查它,我在测试函数名称上看到了这个 linting 错误。

This inspection reports identifiers in android projects which are not accepted by the Android runtime (for example, method names containing spaces)

当我将测试函数从 重命名My space name testing为 时mySpaceNameTesting,测试运行。

难道AndroidJunit4运行时真的不支持带空格的测试函数名吗?

4

1 回答 1

6

正确,Android 运行时不支持它。请参阅此处的编码约定页面。具体来说:

在测试中(并且仅在测试中),可以使用带有反引号的空格的方法名称。(请注意,Android 运行时当前不支持此类方法名称。)测试代码中也允许方法名称中的下划线。

于 2018-07-27T21:04:50.783 回答