首页 > 解决方案 > 测试不是注释类型

问题描述

在我的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>

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

public class Test{


    @Test
    public void test() {

    }

}

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

import org.testng.annotations.Test;

但它再次抱怨:

The import org.testng.annotations.Test conflicts with a type defined in the same file

我已经多次通过 maven 强制更新我的项目,但仍然没有成功。

标签: eclipsemaventestng

解决方案


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


推荐阅读