使用gradle,错误:找不到符号@Test

时间:2017-04-08 17:21:58

标签: java junit build.gradle junit4

我正在尝试使用项目中的gradle构建测试。

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

我收到错误的文件 - >

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]);
        }

    }
}

当我在文件中评论@TEST时,gradle成功构建了测试。

我已经google了很多,但是无法得到错误。

我正在使用junit 4.10

1 个答案:

答案 0 :(得分:2)

应该是:

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

而不是

@TEST
public void test_prepareSearchURL() {
  ..
}

您可以查看how to get started with Junit here