有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java Android重建项目,包组织。junit不存在错误

Error:(3, 17) error: package org.junit does not exist
Error:(5, 24) error: package org.junit does not exist
Error:(11, 6) error: cannot find symbol class Test
Error:(13, 9) error: cannot find symbol method assertEquals(int,int)
:app:compileDebugUnitTestJavaWithJavac FAILED
Error:Execution failed for task ':app:compileDebugUnitTestJavaWithJavac'

Compilation failed; see the compiler error output for details.

当我运行重建时,错误就是这些。但我可以运行我的应用程序而无需重建

我不使用test,我不知道它是如何出现在我的文件夹中的

代码是:

import org.junit.Test;

import static org.junit.Assert.*;

/**
 * To work on unit tests, switch the Test Artifact in the Build Variants view.
 */
public class ExampleUnitTest {
    @Test
    public void addition_isCorrect() throws Exception {
        assertEquals(4, 2 + 2);
    }
}

共 (1) 个答案

  1. # 1 楼答案

    将此添加到您的构建中。格拉德尔

    dependencies {
        ...
        testCompile 'junit:junit:4.12'
    }