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

查看:136
本文介绍了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#的过程一直是编写一些功能,用交互式控制台与他们一起玩,直到我合理地确定他们工作,并调整&结合。这对欧拉项目这样的小规模问题非常有效,但我无法想象如何构建大型项目。

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#编写的:

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#:

  • NaturalSpec
  • FsCheck
  • FsTest
  • FsUnit

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天全站免登陆