简体   繁体   中英

Unit test for POJO using Mockito

I have a POJO class with another POJO variable

class Rows 
{
    private List<RowName> rowName; //RowName is another POJO with String variables
    //getter & setter
}

The test case passes, but I am not sure I am testing this correctly.

public class RowsTest
{
    private final List<RowName> rowName = Mockito.mock(List.class);
    
    private final Rows target = new Rows(rowName);

    @Test
    public void testGetMethods()
    {
        //then
        Assert.assertEquals(rowName, target.getRowName());
    }
}

When writing Mock tests you need to think "What functionality am I locking in so it cannot unexpectedly change in the future"

Testing data classes only ensures Java doesn't break it in the future, and Java has tests for that in their release cycle on the next versions.

Test logic you have which is custom to your program, but not the libraries and languages you use.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM