JUnit 5 的 Assert class 的编译错误
Compilation error for Assert class with JUnit 5
我为 JUnit 5 添加了 Eclipse 依赖项:
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.1.0</version>
<scope>test</scope>
</dependency>
但是当我编译 maven 项目时,我得到了多个这样的错误:
[ERROR] /Users/Documents/rest_api/src/test/java/org/datalis/rest/api/poc/DatabaseFeaturesIntegerTest.java:[135,17] cannot find symbol
[ERROR] symbol: variable Assert
[ERROR] location: class org.api.poc.DatabaseFeaturesIntegerTest
你知道我怎么解决这个问题吗?
从第 5 单元开始,您不再使用断言,但 org.junit.jupiter.api.Assertions
您可以检查this tutorial。
此编译错误:
cannot find symbol
symbol: variable Assert
意味着 Assert
没有被编译器解析,如果你引用 JUnit Assert
class 而没有事先导入它是有意义的,例如:
import org.junit.Assert;
public class DatabaseFeaturesIntegerTest { ... }
请注意 org.junit.Assert
用于 Junit 4 测试 classes.
对于 JUnit 5 测试 classes,您必须使用 org.junit.jupiter.api.Assertions
。
请注意,在 JUnit 5 中使用 org.junit.Assert
是完全有效的,但只有在您想要编译和 run vintage JUnit test classes(JUnit 4 或 3)时才应该这样做。
我为 JUnit 5 添加了 Eclipse 依赖项:
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.1.0</version>
<scope>test</scope>
</dependency>
但是当我编译 maven 项目时,我得到了多个这样的错误:
[ERROR] /Users/Documents/rest_api/src/test/java/org/datalis/rest/api/poc/DatabaseFeaturesIntegerTest.java:[135,17] cannot find symbol
[ERROR] symbol: variable Assert
[ERROR] location: class org.api.poc.DatabaseFeaturesIntegerTest
你知道我怎么解决这个问题吗?
从第 5 单元开始,您不再使用断言,但 org.junit.jupiter.api.Assertions
您可以检查this tutorial。
此编译错误:
cannot find symbol
symbol: variable Assert
意味着 Assert
没有被编译器解析,如果你引用 JUnit Assert
class 而没有事先导入它是有意义的,例如:
import org.junit.Assert;
public class DatabaseFeaturesIntegerTest { ... }
请注意 org.junit.Assert
用于 Junit 4 测试 classes.
对于 JUnit 5 测试 classes,您必须使用 org.junit.jupiter.api.Assertions
。
请注意,在 JUnit 5 中使用 org.junit.Assert
是完全有效的,但只有在您想要编译和 run vintage JUnit test classes(JUnit 4 或 3)时才应该这样做。