F# 开发和单元测试? [英] F# development and unit testing?

查看:29
本文介绍了F# 开发和单元测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚开始使用 F#,这是我的第一个函数式语言.我一直在使用 C#,并且非常享受 F# 引导我重新思考如何编写代码的方式.我觉得有点迷惑的一个方面是编写代码过程的变化.我已经在 C# 中使用 TDD 多年了,非常感谢通过单元测试来了解我所处的位置.

I just got started with F#, which is my first functional language. I have been working quasi-exclusively with C#, and enjoy a lot how F# leads me to re-think how I write code. One aspect I find a bit disorienting is the change in the process of writing code. I have been using TDD for years in C# now, and really appreciate to have unit tests to know where I am at.

到目前为止,我使用 F# 的过程是编写一些函数,在交互式控制台中使用它们,直到我合理地"确定它们可以工作,然后调整 &结合.这在 Euler 项目等小规模问题上效果很好,但我无法想象以这种方式构建大型问题.

So far, my process with F# has been to write some functions, play with them with the interactive console until I am "reasonably" sure they work, and tweak & combine. This works well on small-scale problems like the Euler Project, but I can't imagine building something large that way.

人们如何进行单元测试并为 F# 程序构建测试套件?是否有等效于 TDD 的方法?任何指针或想法表示赞赏.

How do people approach unit testing and building a test suite for a F# program? Is there an equivalent to TDD? Any pointers or thoughts are appreciated.

推荐答案

测试驱动的开发人员应该在 F# 等函数式语言中感到宾至如归:提供确定性可重复结果的小函数非常适合单元测试.F# 语言中还有一些有助于编写测试的功能.例如,对象表达式.你可以很容易地为将接口类型作为输入的函数编写假代码.

Test-driven developers should feel right at home in functional languages like F#: small functions that give deterministically repeatable results lend themselves perfectly to unit tests. There are also capabilities in the F# language that facilitate writing tests. Take, for example, Object Expressions. You can very easily write fakes for functions that take as their input an interface type.

如果有的话,F# 是一流的面向对象语言,您可以使用在 C# 中执行 TDD 时使用的相同工具和技巧.还有一些用 F# 编写或专门为 F# 编写的测试工具:

If anything, F# is a first-class object-oriented language and you can use the same tools and tricks that you use when doing TDD in C#. There are also some testing tools written in or specifically for F#:

Matthew Podwysocki 写了一个很棒的 系列 函数式语言中的单元测试.鲍勃叔叔还写了一篇发人深省的文章此处.

Matthew Podwysocki wrote a great series on unit testing in functional languages. Uncle Bob also wrote a thought provoking article here.

这篇关于F# 开发和单元测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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