Java 初学者使用 JUnit 测试 ArrayList 大小

Yos*_*sia 3 java junit

    @Test
    @DisplayName("Get all Points in Shape is working and gets the correct number output")
    public void test_Get_All_Points_On_Shape()
    {
        ArrayList<Point> points = new ArrayList<Point>(Arrays.asList(new Point[4]));
        assertEquals(points.size() == 4);
    }
Run Code Online (Sandbox Code Playgroud)

上面的代码给出了一个错误

The method assertEquals(short, short) in the type Assertions is not applicable for the arguments (boolean)
Run Code Online (Sandbox Code Playgroud)

如何解决这个问题?

小智 8

要么你用

assertTrue(points.size() == 4);
Run Code Online (Sandbox Code Playgroud)

或者

assertEquals(4, points.size());
Run Code Online (Sandbox Code Playgroud)