Intellij Gradle 项目无法解析 assertEquals,junit 4.11 作为 testCompile dep
2022-09-04 07:11:34
我正在尝试在最新版本的Intellij IDEA(13.0.2)中设置一个简单的gradle项目。
除了JUnit 4之外,我没有其他依赖项,我的build.gradle文件看起来像这样:
apply plugin: 'java'
sourceCompatibility = 1.5
version = '1.0'
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.11'
}
我试图在我的Main类测试套件中使用assertEquals,但是Intellij给了我“无法解析方法assertEquals(int,int)”,用于以下两个实例:
package ag.kge;
import org.junit.Before;
import org.junit.Test;
import org.junit.Assert.*;
public class MainTest {
Main testMain1;
Main testMain2;
@Before
public void setUp(){
testMain1 = new Main("9999");
testMain2 = new Main("args");
}
@Test
public void testGetPort() throws Exception {
assertEquals (testMain1.getPort(), 9999);
assertEquals (testMain2.getPort(), 5000);
}
@Test
public void testStartThreads() throws Exception {
}
}
此外,Intellij 指示告诉我未使用 import org.junit.Assert.*。
如果有人知道我为什么遇到这个问题,我将不胜感激。谢谢。