Android Studio 2.1:错误:包org.junit不存在 [英] Android Studio 2.1: error: package org.junit does not exist

查看:1066
本文介绍了Android Studio 2.1:错误:包org.junit不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新:这是一个错误并且已经报告,请注明:

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

公共类RandomTestClass
{
@Test
public void testTest()
{
assertThat(4,is(4));
}
}

然而,当我去运行测试时,我得到:


错误:包org.junit不存在


我按照文档中的描述完全设置了我的gradle:

  dependencies {
//必需 - JUnit 4框架
testCompile'junit:junit:4.12'
//可选 - Mockito框架
testCompile'org.mockito:mockito-core:1.10.19'
}

此问题的其他几个问题似乎表明缺少这些依赖关系。我有他们。



当我去运行测试时,您能想到我的本地单元测试没有找到junit文件的原因吗?



注意
我可以在编写代码时找到junit类。当我运行测试时,它只能找不到junit。

解决方案

看起来Gradle没有做到这一点。



手动添加罐子解决了问题。


Update: Its a bug and it's been reported, please star: https://code.google.com/p/android/issues/detail?id=209832&thanks=209832&ts=1463161330

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 src/test/java

I've made a random test class:

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

public class RandomTestClass
{
    @Test
    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?

Note 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.

这篇关于Android Studio 2.1:错误:包org.junit不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆