java - Junit 5 中的多项测试
问题描述
我研究了如何使用 JUnit 5 并遇到了一个问题。我看了很多示例并阅读了有关此问题的信息,但无法决定。所以,如果我想测试一个测试,这是可行的,我会得到结果。但是,如果我添加多个测试(2 个或更多),则会出错。我的主类代码。
public class Project1_Temp {
Project1_Temp(){
}
public static int plusTest(int a, int b) {
return a+b;
}
}
我的类测试代码
import static org.junit.jupiter.api.Assertions.*;
import java.util.Arrays;
import java.util.Collection;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameter;
import org.junit.runners.Parameterized.Parameters;
@RunWith(Parameterized.class)
class Project1_TempTest {
int a,b,expResult;
//@Parameter(0)
/*public int a;
//@Parameter(1)
public int b;
//@Parameter(2)
public int expResult;
*/
@Parameterized.Parameters
public static Collection<Object[]> data() {
//Object[][] data = new Object[][] { { 1 , 2, -5 }, { 5, 3, 15 }, { 121, 4, 484 } };
return Arrays.asList(new Object[][] {{1,2,3},{0,0,0},{5,2,7},{2,2,5}});
}
Project1_TempTest(int a, int b, int expResult){
this.a = a;
this.b = b;
this.expResult = expResult;
}
@Test
void test() {
assertEquals(expResult, Project1_Temp.plusTest(a, b));
}
}
我得到这个错误:
no parameterresolver registered for parameter int arg0 in constructor
我查看了不同的论坛,讨论了这个错误,但不明白,我怎么能决定它。请帮帮我 :)
解决方案
推荐阅读
- splunk - 如何编写 Splunk 查询以获取每个源的第一个和最后一个请求时间以及表输出中的每个源计数
- ios - Flutter 应用程序的 iOS 构建中的模块“未找到连接”
- mysql - mysqlbinlog 在 Google Cloud SQL MySql 中不起作用
- java - 找不到带有 VSCode 类的 JDBC
- dojox.grid.datagrid - 为什么我的页面没有呈现 EnhancedGrid
- c++ - 分割核心转储在我的代码中以实现“哈夫曼编码”
- r - R:$ 不能用于原子向量(箱线图)
- authentication - 如何使用 Blazor 结合 Google 身份验证和 API 密钥身份验证?
- java - Geoserver ogcapi 插件 jar 库未加载
- javascript - uppy 如何将元字段从仪表板添加到 XHRUpload