Java – Intellij Gradle project cannot resolve assertEquals with junit 4.11 as the testCompile dep

gradleintellij-ideajavajunit

I'm trying to set up a simple gradle project in the latest version of Intellij IDEA (13.0.2).

I have no dependencies other than JUnit 4, my build.gradle file looks like this:

apply plugin: 'java'

sourceCompatibility = 1.5
version = '1.0'

repositories {
    mavenCentral()
}

dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.11'
}

I'm trying to use assertEquals in my Main class test suite, but Intellij is giving me the "Cannot resolve method assertEquals(int, int)" for the following two instances of it's use:

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 {

    }
}

Also, Intellij indicates tells me that the import org.junit.Assert.* isn't used.

If anyone knows why I'm having this problem, I'd really appreciate the help.
Thanks.

Best Answer

import org.junit.Assert.*;

should be

import static org.junit.Assert.*;
Related Topic