英文:
Unit test for POJO using Mockito
问题
我有一个包含另一个POJO变量的POJO类
```java
class Rows
{
private List<RowName> rowName; //RowName是另一个具有String变量的POJO
//getter和setter
}
测试案例通过了,但我不确定我是否在正确地进行测试。
public class RowsTest
{
private final List<RowName> rowName = Mockito.mock(List.class);
private final Rows target = new Rows(rowName);
@Test
public void testGetMethods()
{
//然后
Assert.assertEquals(rowName, target.getRowName());
}
}
英文:
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());
}
}
</details>
# 答案1
**得分**: 0
在编写模拟测试时,您需要考虑:“我要锁定哪些功能,以便它们在将来不会意外更改。”
仅测试数据类可以确保 Java 在将来不会破坏它,而 Java 已经在其发布周期中对其进行了测试,适用于下个版本。
测试您的程序中与您的自定义逻辑有关的部分,但不包括您使用的库和语言。
<details>
<summary>英文:</summary>
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.
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论