Andriy
Andriy

Reputation: 805

Unit tests terminated in Debug mode

I'm using IntelliJ IDEA 15.0.2 (Community Edition) under Windows 7 and Windows 10 Pro, Gradle 2.9, JDK 1.7.0_65. Operating systems installed as guests under VMware Workstation 11.1.3

I have created Android Gradle application with single empty activity and wanted to check how unit test support works. There is a single unit test module ApplicationTest.java created by IDE, it contains only constructor. Right-clicking on [java] folder I created 'All in Module' JUnit3 test configuration.

Tests complete successfully when I Run them, however fail if I Debug the configuration. Failure reason says 'Terminated' (screenshot, IDEA log) which explained in the documentation as 'Test terminated. This status is assigned to tests that were cancelled by clicking the Stop button'. Just want to confirm that I didn't click the Stop button.

Logcat logs don't report any failures, IDE log reports 2 tests passed too. However problem remains as IntelliJ still reports a termination.

Sometimes I also getting 'Test framework quit unexpectedly' error and no tests succeed.

I've done some research and found similar questions, no real solutions mentioned. Have strong suspicion that this is a configuration issue.

What do I do wrong?

Upvotes: 9

Views: 9269

Answers (4)

Top-Master
Top-Master

Reputation: 8796

In my company's case, the fix was to:

  1. Open Edit Configuration... for All tests (or whatever you renamed it into).
  2. Switch to Debugger tab.
  3. And finally, in Debug mode combo-box, select the Java option, because:
    • Although we have lots of Native codes, Android-studio 3.2.1 (which we were using) does not seem to support debugging both (but Java only mode works fine).

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.

Upvotes: 2

Fox
Fox

Reputation: 417

In my situation, the problem is solved by setting in the test's run configuration: Shorten command line -> JAR manifest.

Upvotes: 0

Mohsen Dianati
Mohsen Dianati

Reputation: 1

To get rid of unit test problems in debug mode, I deleted all test folders in android studio explorer, then I commented three test implementation lines in build.gradle(module) file. Then I changed the combobox in android studio menu (top of the IDE) from "all in app" to "app".

https://i.sstatic.net/alPrS.png

Upvotes: -1

MattMatt
MattMatt

Reputation: 2310

Gabor's suggestion seemed to fix this issue for me. On a Mac (and I presume on a Windows machine, but with a different route to get there) go to Preferences:

From the menu bar at the top Android Studio → Preferences

or

Hit ⌘ and , to jump straight to it.

Then in the menu search box type "instant". Uncheck the box that says "Enable instant run..", which looks like the image below.

enter image description here

That fixed it for me; didn't even need to restart/kill ADB.

It seems to be enabled by default, and I use it often to hot-swap changes during development, so I didn't think to turn it off when running Espresso tests.

Upvotes: 0

Related Questions