0

I am using Android studio 1.5.1. My build.gradle looks like below

allprojects {
        repositories {
            maven { url 'http://repo1.maven.org/maven2' }
        }
    }

    buildscript {
        repositories {
            jcenter()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:1.5.0'
        }
    }
    apply plugin: 'com.android.application'

    dependencies {
        // Unit testing dependencies
        testCompile 'org.hamcrest:hamcrest-library:1.3'
        testCompile 'junit:junit:4.12'
    }

I am writing some JUNIT test cases for my application as below

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;

public void testSomething throws Exception {
        ...
        assertThat(result, is(true));
}

But when I am running the tests, it is showing that

error: package org.hamcrest does not exist

error: cannot find symbol assertThat(result, is(true));

But I can go to the definition of assertThat, org.hamcrest etc from studio by going to definition as studio decompiles the jars. Also I can see the package downloaded in .gradle/caches

Can anyone suggest what I am doing wrong here? Normally Junit test cases using assertFalse, assertTrue etc is working, only hamcrest matching is giving errors.

dinotom
  • 4,990
  • 16
  • 71
  • 139
Deepu
  • 598
  • 6
  • 12

1 Answers1

2

Manually add the jar from here

Add it to your libs folder.

Right click the jar, and click add as library.

I had the same issue with getting it to find junit. Looks like Gradle is not doing its job.

I have filed a bug report, Please star: https://code.google.com/p/android/issues/detail?id=209832&thanks=209832&ts=1463161330

Aggressor
  • 13,323
  • 24
  • 103
  • 182