Adam Styrc
Adam Styrc

Reputation: 1537

Android Junit - "Class not found"

For my Android project I'd like to test pure Java code. To achieve this, I want to use JUnit.

Due to known bug:

!!! JUnit version 3.8 or later expected:
java.lang.RuntimeException: Stub!
    at junit.runner.BaseTestRunner.<init>(BaseTestRunner.java:5)
    at junit.textui.TestRunner.<init>(TestRunner.java:54)
    at junit.textui.TestRunner.<init>(TestRunner.java:48)
    at junit.textui.TestRunner.<init>(TestRunner.java:41)
    at com.intellij.rt.execution.junit.JUnitStarter.junitVersionChecks(JUnitStarter.java:190)
    at com.intellij.rt.execution.junit.JUnitStarter.canWorkWithJUnitVersion(JUnitStarter.java:173)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:56)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134) 

I installed proper plugin to Android Studio and added:

classpath 'com.github.jcandksolutions.gradle:android-unit-test:2.1.1'

and in app build.gradle

apply plugin: 'android-unit-test'

dependencies {
    testCompile('junit:junit:4.11')
}

As JUnit was added I wrote simple test class in src/androidTest/java/com.adamstyrc.mytrack.unit:

package com.adamstyrc.mytrack.unit;


import junit.framework.TestCase;

public class SimpleTest extends TestCase {

    public void testName() {
        assertEquals(7, 6);
    }
} 

But what I get is:

Class not found: "com.adamstyrc.mytrack.unit.SimpleTest"

Why is it not visible ?

Upvotes: 2

Views: 2862

Answers (1)

Adam Styrc
Adam Styrc

Reputation: 1537

OK, as https://github.com/JCAndKSolutions/android-unit-test says the path has to be:

src/test/...

instead of src/androidTest/

and nothing like:

sourceSets {
    androidTest {
        setRoot('src/androidTest') 
    }
}

can change it.

Upvotes: 2

Related Questions