Search code examples
javajunitbuild.gradlejunit4

using gradle, error: cannot find symbol @Test


I am trying to build the tests using gradle in the project.

On building the tests, I am getting error ->
:compileTestJava/home/vibhcool/Documents/github/loklak_server/test/org/loklak/harvester/TwitterScraperTest.java:28: error: cannot find symbol
@TEST
 ^
symbol:   class TEST
location: class TwitterScraperTest
1 error
FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':compileTestJava'.

The file in which I am getting error ->

package org.loklak.harvester;

import java.io.File;
import java.io.IOException;
import org.junit.After;
import org.junit.Before;
import org.loklak.harvester.TwitterScraper;
import org.junit.Test;
import static org.junit.Assert.assertEquals;

public class TwitterScraperTest {

    @TEST
    public void test_prepareSearchURL() {
        String url;
        String[] query = {"q1", "q2", "q3", };
        String[] out_url = {"url1", "url2", "url3"};

        for (int i = 0; i < query.length; i++) {
            url = TwitterScraper.prepareSearchURL(query[i]);
            assertEquals(url, out_url[i]);
        }

    }
}

When I comment @TEST in the file, gradle successfully builds the tests.

I have googled a lot but, not able to get the error.

I am using junit 4.10


Solution

  • It should be :

    @Test
    public void test_prepareSearchURL() {
      ...
    }
    

    and not

    @TEST
    public void test_prepareSearchURL() {
      ..
    }
    

    You can take a look on how to get started with Junit here.