如何对转换库进行单元测试? [英] How to unit test a conversion library?
问题描述
我刚刚开始使用 C# 进行单元测试.
我已经阅读了很长时间关于单元测试的文章,而且我已经在玩 NUnit,但这是我第一次尝试为真正的代码编写真正的测试.
I'm just starting out with unit testing in C#.
I have been reading about unit testing for a long time now, and I've already been playing around with NUnit, but this is the first time that I actually try to write real tests for real code.
但我的问题是:
我很难想出我可以实际测试的东西.
But my problem is:
I'm having a hard time to come up with things that I can actually test.
我要测试的项目是一个转换库(将 POCO 列表转换为 ADO 记录集).
The project I want to test is a conversion library (to convert lists of POCOs to ADO Recordsets).
到目前为止,我只提出了两个要测试的东西:
So far, I've come up with only two things to test:
- 如果记录集完全存在(非 Null,非空)
- 如果每个字段的内容都一样(--> if
RS!Foo == POCO.Foo
)
所以,我的问题是:
- 当我的代码只是将 A 转换为 B 时,我还能测试什么?
- 或者这个项目太小/太简单/不是一个很好的例子来编写多个有意义的单元测试?
推荐答案
有很多东西需要测试.我还建议考虑并可能进行验证:
There are quite a few things to test. I would also suggest thinking about and potentially verifying:
POCO
的私有字段没有正确映射- 列表中的无效条目正确抛出异常
- 记录集长度正确
- 根据需要处理 POCO 中的继承(即:基类成员按预期映射)
- Private fields of
POCO
don't map through correctly - Invalid entries in the list throw exceptions correctly
- Recordset length is correct
- Inheritance in POCO is handled as desired (ie: base class members map through as expected)
这篇关于如何对转换库进行单元测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!