测试不是注释类型

Jef*_*eff 1 eclipse testng maven

在我的Maven项目中,我添加了testng依赖项,如下所示:

<!-- https://mvnrepository.com/artifact/org.testng/testng -->
<dependency>
    <groupId>org.testng</groupId>
    <artifactId>testng</artifactId>
    <version>7.1.0</version>
    <scope>test</scope>
</dependency>
Run Code Online (Sandbox Code Playgroud)

但是,当我编写如下简单测试时,它找不到@Test

public class Test{


    @Test
    public void test() {

    }

}
Run Code Online (Sandbox Code Playgroud)

它抱怨Test is not an annotation type 我尝试通过以下行手动添加测试:

import org.testng.annotations.Test;
Run Code Online (Sandbox Code Playgroud)

但它再次抱怨:

The import org.testng.annotations.Test conflicts with a type defined in the same file
Run Code Online (Sandbox Code Playgroud)

我已经通过 Maven 强制更新我的项目好几次了,但仍然没有成功。

小智 5

它不起作用,因为您的类名也是“Test”,因此,您必须更改类名,然后只有 @Test 注释才能工作。