简体   繁体   English

使用 Mockito 对 POJO 进行单元测试

[英]Unit test for POJO using Mockito

I have a POJO class with another POJO variable我有一个带有另一个 POJO 变量的 POJO 类

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"在编写 Mock 测试时,您需要考虑“我锁定了什么功能,以便将来不会意外更改”

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.测试数据类只能确保 Java 将来不会破坏它,并且 Java 在下一个版本的发布周期中对此进行了测试。

Test logic you have which is custom to your program, but not the libraries and languages you use.测试您的程序自定义的逻辑,而不是您使用的库和语言。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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