F # Monomer Testing

Source: Internet
Author: User

I've been trying to write some F # code recently. However, I am accustomed to TDD, I feel a little uncomfortable, is not what is the disadvantage? Yes, the monomer test. After a search and investigation I decided to try Fsunit. The Learning notes for the sample code combined with this framework are as follows.

(* Add Reference *)
#r "FsUnit.NUnit.dll"
#r "Nunit.framework.dll"
(* Import namespaces *)
Open Nunit.framework
Open Fsunit
(* Definition of the tested class *)
Type lightbulb (state) =
member X.on = State
Override x.tostring () =
Match X.on with
| True-> "on"
| False-> "Off"
(*
First, a testfixture is defined by attribute.
When Setup generates a lightbulb instance, the initial state is true.
The testfixture contains two test methods that test the on property and the ToString method, respectively.
The naming of test methods is very distinctive. Test assertions are also very close to natural languages by using pipelines.
*)
[<testfixture>]
Type ' Given a lightbulb that has had its state set to True ' () =
Let lightbulb = new Lightbulb (true)
[<test>] member X.
' When I ask whether it's on it answers true. ' () =
Lightbulb.on |> should be True
[<test>] member X.
' When I convert it to a string it becomes ' on '. ' () =
String lightbulb |> should equal "on"
[<testfixture>]
Type ' Given a lightbulb that has had its state set to False ' () =
Let lightbulb = new Lightbulb (false)
[<test>] member X.
' I ask whether it's on it answers false ' () =
Lightbulb.on |> should be False
[<test>] member X.
' When I convert the it to a string it becomes. ' () =
String lightbulb |> should equal "off"

Fsunit is a xunit member that faces F #. With such a single test framework, we can write code more confidently.

SOURCE http://bj007.blog.51cto.com/1701577/347752

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.