在进行 TDD 时处理转换方法的最佳方法是什么? [英] What is the best way to deal with conversion methods when doing TDD?

查看:70
本文介绍了在进行 TDD 时处理转换方法的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在尝试进行测试驱动开发时处理方法中发生的转换的最佳实践是什么?

What is the best practice is for dealing with conversions that occur in methods when trying to do test driven development?

是否创建静态实用方法来执行转换,然后对这些实用方法编写单元测试?我觉得问题在于当您针对调用此实用程序方法的父方法编写测试时,您必须考虑发生的转换,因为大多数模拟框架不模拟实用程序方法.因此,编写处理父方法的验证方法变得困难.

Is it to create static utility methods that perform the conversions and then write unit tests on those utility methods? I feel like the problem with that is when you write tests against the parent method that calls this utility method, you have to account for the conversion occurs, since most mocking frameworks do not mock utility methods. Therefore, writing verification methods that deal with the parent method becomes difficult.

我想到的另一个选择是创建一个负责转换的接口,并在测试调用方法时模拟该接口.接口旁边会有一个实现.这样做的问题是似乎正在编写额外的代码来进行转换,并且在配置 IOC 容器时需要考虑许多新的依赖项.

The other option I've thought of would be to create an interface responsible for the conversions, and mock out that interface when testing the calling method. There would be an implementation sitting next to the interface. The problem with this is it seems like extra code is being written just to do the conversions, and a lot of new dependencies need to be accounted for when configuring the IOC container.

一个完美的例子是一个控制器动作,它需要从视图模型转换为实体,该实体是它所连接的服务的输入.这方面的最佳做法是什么?

A perfect example is a controller action that needs to convert from the view model to the entity that is the input for the service it connects to. What's best practice for this?

推荐答案

您可以Moq 有关更多信息,如何在 TDD 中使用最小起订量,请查看以下链接

You can Moq for more information, how to use the moq with TDD check the below link

TDD:Moq 简介

有关 TDD 的更多信息,请查看以下链接

And also for for more info about TDD check below links

TDD/BDD 截屏/视频资源

使用极限编程技术改进项目的设计和灵活性

使用 C# 和RhinoMocks

这篇关于在进行 TDD 时处理转换方法的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆