java - 测试多个文件并查看每个文件的结果的最佳方法或 method() 是什么?
问题描述
我正在使用 Intellij IDEA 2019 和 junit 读取一堆文件,处理它们,看看我是否得到了正确的结果。这是我的代码:
@Test
public void testSolution() {
Solver s;
Board b;
int counter = 0;
final File folder = new File("C:\\Users\\IdeaProjects\\EightPuzzle\\src\\ModifiedTests");
for (final File fileEntry : folder.listFiles()) {
System.out.println("processing file: " + fileEntry.getName());
In in = new In(fileEntry.getAbsolutePath());
int n = in.readInt();
int moves = in.readInt();
int[][] tiles = new int[n][n];
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
tiles[i][j] = in.readInt();
b = new Board(tiles);
s = new Solver(b);
assertEquals(s.moves(), moves);
counter++;
if (counter > 10) break;
}
}
这是一个示例文件:
3
24
6 5 3
4 1 7
0 2 8
有什么方法可以查看哪些文件已被处理,结果如何?我一直在尝试使用 assertEquals 方法中的消息字段,但我不知道访问结果的方法。我可能需要不同的方法?
解决方案
如果我理解你的问题是正确的,也许参数化测试是你的解决方案,你的目录中的文件是参数。请检查:
https://junit.org/junit4/javadoc/4.12/org/junit/runners/Parameterized.html
推荐阅读
- mysql - MySQL - 查找第一个匹配项或通配符
- python - 根据其他列中的数据创建动态列
- java - Java中自定义对象的空检查
- tags - 仅在未指定标签时运行 ansible 任务
- elasticsearch - 如何在 Elasticsearch 中修复“curl: (23) Failed writing body (4096 != 9142)”
- wcf - 使用 SwaggerWcf 时如何查看我的 Swagger 文档?
- forms - 内联表单输入和提交按钮在屏幕宽度 < 576 像素处未对齐
- python-2.7 - pypi 上 GEOS 的更高版本
- python - 使用 Python 合并 PDF 文件
- php - 如何将 API 请求限制为每个用户同时一个?