1

I've run into very strange error.

When i try to run test that are in my Kotlin class in androidTest package they are running as test junit mehthods and this error appears:

Process finished with exit code 1 Class not found: "com.someampp.shoppinglistapp.SomeClassTest"Empty test suite.

You can try it for yourself. I am using Android Studio 3.0.1

When i am creating class like this in Java:

@RunWith(AndroidJUnit4.class)
public class SomeTestClass{
@Test
public void useAppContext() throws Exception {
    // Context of the app under test.
    Context appContext = InstrumentationRegistry.getTargetContext();

    assertEquals("com.myapp.shoppinglistapp", appContext.getPackageName());
  }
}

Everything works fine.

But when i convert the Java file to Kotlin:

@RunWith(AndroidJUnit4::class)
class SomeTestClass{
@Test
@Throws(Exception::class)
fun useAppContext() {
    // Context of the app under test.
    val appContext = InstrumentationRegistry.getTargetContext()

    assertEquals("com.myapp.shoppinglistapp", appContext.packageName)
  }
}

It gives me this error.

Whats wrong?

K.Os
  • 5,123
  • 8
  • 40
  • 95

1 Answers1

2

You need to open Run/Debug configurations and create one for Android Instrumented Tests instead of Android JUnit.

Alexey Romanov
  • 167,066
  • 35
  • 309
  • 487