
问题:如何使用junit5,对同一测试样例不同方法进行测试?
需求:
解决方案:
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
public class Sort_Test3 {
private int[] runTest_Data;
// 每一次测试之前,都生成一份新的随机测试数据
@BeforeEach
void init_() {
this.runTest_Data = init_All();
System.out.println("run...");
}
// 具体测试方法
@Test
public void test_mpSort() {
int[] mp = MySortAlgorithm_Main.mp_sort(runTest_Data);
System.out.println("冒泡排序结果:");
}
@Test
public void test_choseSort() {
int[] cos = MySortAlgorithm_Main.chose_sort(runTest_Data);
System.out.println("选择排序结果:");
}
@Test
public void test_insertSort() {
int[] ins = MySortAlgorithm_Main.insert_sort(runTest_Data);
System.out.println("插入排序结果:");
}
// 其他测试方法
private int[] init_All() {
// 随机生成测试数据
int n = (int) (Math.random() * 1000);
System.out.println(n);
int[] testData = new int[n];
for (int i = 0; i < n; i++) {
testData[i] = (int) (Math.random() * 1000);
}
return testData;
}
}说明:
以上就是如何使用 JUnit5 对同一测试用例的不同排序算法进行测试?的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号