trocchietto trocchietto - 1 year ago 176
Android Question

Junit 4 does not recognize test

I cloned a repository and tried to run a test. Unfortunately, JUnit 4 does not recognize the directory that I added manually

The test GUI says after tries to load the tests:

No tests were found.

Tests ran to completion.

Empty test suite.

This is my directory with
that i copypasted by another project (this is a default file that is not questionable that does not work)

enter image description here

And this is my

apply plugin: ''

android {
compileSdkVersion 23
buildToolsVersion "23.0.3"

defaultConfig {
testApplicationId ""

dependencies {
compile 'com.squareup.retrofit:retrofit:1.6.1'
compile 'de.greenrobot:eventbus:2.2.1'
testCompile 'junit:junit:4.12'
androidTestCompile ''

EDIT as requested here the content of ExampleUnitTest and Run/Debug Configurations.


* To work on unit tests, switch the Test Artifact in the Build Variants view.
public class ExampleUnitTest {
public void addition_isCorrect() throws Exception {
assertEquals(4, 2 + 2);

Run/Debug Configurations
enter image description here

Answer Source

First, ensure Android Studio don't see any test in Run/Debug Configurations menu. To do that, click on Edit Configurations... option and then check JUnit section on the left.

enter image description here

If there are no tests, click enter image description here, select JUnit, select app module and ExampleUnitTest class. Don't forget to apply changes and then try to run test again.

enter image description here

If this does not help, please try switching from Release to Debug build variant and ensure there is no stacktrace of the exception in Android Monitor tab.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download