AndroidJunit4 doesn't accept space function test name?
Asked Answered
A

1

13

I have the following test, where the test name is with space and backtick for my instrumental test

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

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

However when running it, it can't be executed (i.e. No test were found)

Checking on it, I saw this linting error on the test function name..

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

When I rename my test function from My space name testing to mySpaceNameTesting, the test run.

Is it really that AndroidJunit4 runtime can't support test function name with spaces?

Adriaadriaens answered 27/7, 2018 at 16:34 Comment(0)
P
12

Correct, it's unsupported in the Android runtime. See the Coding Conventions page here. Specifically:

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.

Pagepageant answered 27/7, 2018 at 21:4 Comment(3)
Seems to have been addressed if you target API 30: android.googlesource.com/platform/art/+/…Philpott
I'm targeting API 31 and it doesn't work yet. Could it be because the Android Gradle Plugin in IntelliJ IDEA is older than the one in Android Studio?Raynaraynah
Seems you have to set minSdkVersion 30+Morphology

© 2022 - 2024 — McMap. All rights reserved.