测试状态变更规则
我在域模型中有一个实体。该实体具有 ChangeStatus(StatusesEnum newStatus) 方法。 StatusesEnum 有超过 10 个成员。它们只能按正确的顺序更改,例如 StatusesEnum.First 可以更改为 Second 和 Third,Third 只能更改为 Fourth,Fourth 可以更改为 Fifth 和 Seventh 等。
ChangeStatus 方法会因错误而引发异常过渡。 我不认为测试所有情况都是正确的(也许我错了:)),但是我如何编写测试来检查正确的转换顺序。
I have an entity in Domain Model. This entity has ChangeStatus(StatusesEnum newStatus) method.
StatusesEnum has more then 10 members. They can be changed only in correct order, for example StatusesEnum.First can be changed to Second and Third, Third can be changed to Fourth only, Fourth can be changed to Fifth and Seventh etc.
ChangeStatus method is throwing exception for wrong transitions.
I don't think that testing all cases is right (maybe I'm wrong :)), however how can I write test for checking right transitions order.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您使用的是 NUnit 2.5 或更高版本,您可以使用
参数化测试
但是,如果我是你,我会创建一个非-抛出将在状态逻辑中使用的决策函数
,并在单元测试中进行测试,因此不再需要
测试异常逻辑
If you are using NUnit 2.5 or later you can use
Parameterized Tests
However if i were you i would create a non-throwing decision-function
that is to be used in you statelogic and is tested in unittest so there is no more need to
test the exception logic
你想有多彻底取决于你自己。我会对每个正确的转换进行测试,例如
对每个输入状态的一个无效转换进行测试:
How thorough you want to be is up to you. I'd have tests for each of the correct transitions, e.g.
And a test for one invalid transition per input state: