Aggressor Aggressor - 5 months ago 109
Java Question

Android Studio 2.1: error: package org.junit does not exist

Update: Its a bug and it's been reported, please star:

I'm setting up unit testing on Android studio.

I have read the documentation and set it up exactly as specified. I have my test folder set up as


I've made a random test class:
enter image description here

import org.junit.Test;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;

public class RandomTestClass
public void testTest()
assertThat(4, is(4));

However when I go to run my test I get:

error: package org.junit does not exist

I've set up my gradle EXACTLY as descibed in the docs:

dependencies {
// Required -- JUnit 4 framework
testCompile 'junit:junit:4.12'
// Optional -- Mockito framework
testCompile 'org.mockito:mockito-core:1.10.19'

The few other questions with this issue seemed to say these dependencies are missing. I have them.

Can you think of any reason my Local Unit Tests are not finding the junit file when I go to run the test?

It's able to find the junit classes when Im writing the code. It only can't find junit when I run the test.


It looks like Gradle is not doing it's job.

Manually adding the jars fixed the problem.