我正在使用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方法中的message字段,但我不知道访问结果的方法。我可能需要一个不同的方法?
发布于 2020-07-13 00:52:03
如果我理解正确的话,也许参数化测试就是您的解决方案,您的目录中的文件就是参数。请检查:
https://junit.org/junit4/javadoc/4.12/org/junit/runners/Parameterized.html
https://stackoverflow.com/questions/62863533
复制相似问题