马文
验证您在 POM 文件中指定的依赖项。您应该在元素中嵌套以下dependencies内容。
<!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.4.0-RC1</version>
<scope>test</scope>
</dependency>
如果在测试类之外调用断言,请在常规应用程序类中删除该<scope>test</scope>元素。
示例类
这是一个简单的测试示例。
package work.basil.example;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* Unit test for simple App.
*/
public class AppTest
{
/**
* Rigorous Test :-)
*/
@Test
public void shouldAnswerWithTrue()
{
assertTrue( true );
}
}
新junit-jupiter神器
请注意,从 JUnit 5.4.0 开始,我们可以指定新的非常方便的单个 Maven 工件,junit-jupiter它反过来将为您的项目提供 8 个库。