3

I have some tests in my Android project. I run them in Android Studio (using "run" button, not command line) and everything is fine - so I guess configuration is correct. When I try to debug them (again, using "debug" button instead of run), it crashes with "Test framework quit unexpectedly" (after showing "Instantiating tests". No other error messages in console or in logcat. It happens both on a real device and emulator, and only in debug mode.

My tests look like this:

@RunWith(AndroidJUnit4.class)
public class InformationTest extends AbstractServiceTest {

@Test
public void testCopyResource(String resourceName, File destination) throws IOException {
        try (InputStream inputStream = getClass().getResourceAsStream(resourceName)) {
            FileUtils.copyInputStreamToFile(inputStream, destination);
        }
    }
}

I have tried to invalidate caches / restart, I do have testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" in build.gradle (found these suggestion for people who weren't able to even run the tests). Anything else I am missing?

ausan
  • 106
  • 1
  • 8

2 Answers2

4

In my case (as mentioned in another post) the fix was to:

  1. Open Edit Configuration... for All tests (or whatever you re-named it into).
  2. Switch to Debugger tab.
  3. In Debug mode combo-box, select the Java option:
    • Although we have lots of Native codes, let's try NOT to debug them while we debug our Integration-tests ;-)

Note that we've seen above since Android-studio 3.2.1 until Android-studio 2022.x, but above might not be required in some newer version.

Top-Master
  • 7,611
  • 5
  • 39
  • 71
  • thank you so much! I encountered this issue in Android Studio Flamingo | 2022.2.1 Patch 1. To be honest, I had no hope until I saw this answer. :) – tugceaktepe May 18 '23 at 09:24
  • Bro I am dealing with this issue for hours. I thought the crash is because of memory related. So I changed VM options, did many changes to increase memory usage. Found out that it wasn't the reason. Your suggestion just saved me. Thank you!!! – Burak Jun 06 '23 at 16:21
1

After a long time, I accidentally found a solution. The tests run fine in debug mode if I disable instant run in Android Studio. (File -> Settings -> Build, Execution, Deployment -> Instant Run, uncheck "enable instant run").

ausan
  • 106
  • 1
  • 8