问题描述
我正在尝试将参数化测试添加到我的Java程序中.我找到了包含JUnit 5的示例.
I am trying to add parameterized tests into my Java program. I found the examples for JUnit 5, which I do have included.
https://blog.codefx.org/libraries/junit-5 -parameterized-tests/
问题是我无法添加@ParameterizedTest,因为缺少名称空间.知道原因或方式.
The issue is I cannot add @ParameterizedTest because the namespace is missing. Idk why or how.
文档页明确指出它在org.junit.jupiter.params中,但我没有.
The documentation page clearly states it is in org.junit.jupiter.params, but I do not have that.
让您对我的代码有所了解:
To give you an idea of my code:
import org.junit.jupiter.api.Test;
import java.util.Arrays;
import java.util.Collection;
import static org.junit.jupiter.api.Assertions.*;
class SubsetPrinterTest
{
// https://blog.codefx.org/libraries/junit-5-parameterized-tests/
static Collection<Object[]> makeSetData()
{
return Arrays.asList(new Object[][]
{
{1, new char[]{'1'}},
{2, new char[]{'1', '2'}},
{3, new char[]{'1', '2', '3'}},
{4, new char[]{'1', '2', '3', '4'}},
{5, new char[]{'1', '2', '3', '4', '5'}}
});
}
// This should be a parameterized test using the makeSetData.
@Test
void makeSet()
{
// Arrange
SubsetPrinter subsetPrinter = new SubsetPrinter();
// Act
char[] set = SubsetPrinter.MakeSet(5);
// Assert
assertArrayEquals(set, new char[]{'1', '2', '3', '4', '5'});
assertEquals(set.length, 5);
}
}
推荐答案
您的项目类路径必须包含junit-jupiter-params-xxx.jar
版本,例如junit-jupiter-params-5.0.0.jar. org/maven2/org/junit/jupiter/junit-jupiter-params/5.0.0/"rel =" noreferrer> http://central.maven.org/maven2/org/junit/jupiter/junit-jupiter-params /5.0.0/
You project class-path has to include a version of junit-jupiter-params-xxx.jar
, like junit-jupiter-params-5.0.0.jar
from http://central.maven.org/maven2/org/junit/jupiter/junit-jupiter-params/5.0.0/
您链接到的codefx.org
中的博客文章说(已编辑为当前的5.0.0版本):
The blog post from codefx.org
you link to says (edited to the current 5.0.0 release):
Group ID: org.junit.jupiter
Artifact ID: junit-jupiter-params
Version: 5.0.0
可以手动下载并添加它,或者如果您使用的是带有依赖项管理的构建工具(Gradle,Maven等),则相应地配置构建脚本(build.gradle,pom.xml等).
Either download and add it manually, or if you're using a build tool with dependency management (Gradle, Maven, ...) configure the build script (build.gradle, pom.xml, ...) accordingly.
在此处找到一些通用示例: https://github.com/junit-team/junit5-样本
Find some generic samples here: https://github.com/junit-team/junit5-samples
从版本 5.4.0-M1 开始,JUnit Jupiter提供了一个聚合器工件,它将所有可用的Jupiter定义工件捆绑在一起,以便于使用.参见 https://sormuras.github.io/blog/2018年12月26日-junit-jupiter-aggregator.html 了解详情.
Starting with version 5.4.0-M1 JUnit Jupiter provides an aggregator artifact that bundles all available Jupiter-defining artifacts for easy consumption. See https://sormuras.github.io/blog/2018-12-26-junit-jupiter-aggregator.html for details.
这篇关于JUnit5中缺少org.junit.jupiter.params的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!