Marc
Marc

Reputation: 219

Is JUnit really unable to find my test class in android studio?

I read the solution to How to run a simple JUnit4 test in Android Studio 1.1? and verified my gradle plugin version is greater than 1.1

Right Clicking my junit 4 test class and selecting run gives this error in android studio:

Cannot find class com.me.android.javamodule.MyTestClass

My android proj dir looks like:

In module "app":
src-->main
src-->test-->java-->com.me.android.working contains WorkingTest.java
src-->test-->java-->com.me.android.javamodule contains MyTestClass.java

"javamodule" is a regular java module that the app module depends on, it is a sibling to the "app" module.

I don't think the error is accurate because I copied "MyTestClass.java" into com.me.android.working, which contains WorkingTest.java, a Junit4 test that CAN run. Android Studio still complains with the same error.

Here is MyTestClass.java

package com.me.android.javamodule;
import org.junit.Before;
import org.junit.Test;

public class MyTestClass {
    private Solver solver;

    @Before
    public void init() {
        solver = new Solver();
    }

    @Test
    public void testReverse() {
        assertTrue(solver.parseStr("woof").equals("foow"));
    }
 }

Upvotes: 1

Views: 1436

Answers (1)

Marc
Marc

Reputation: 219

This worked for me:

  1. right click src and select New Directory, call it test
  2. do the same for test and call it java
  3. right click java and select New Package to create a new package like com.application. unit test can go here.

Upvotes: 1

Related Questions