fharp unit testing
TRANSCRIPT
Unit Testing with F#
Sugak Alexandr
Unit Testing
Functional design is testable by its
nature
Pure function – always returns the same value given the same input
and has no side-effects
Isolated function – a function which knows nothing about the state of
the external world, except information passed via its arguments
A pure function is isolated
Assertion, C# way (MSTest)
Structural Equality
F# has Structural Equality for:
• Records
• Discriminated Unions
• Arrays
• Lists
Assertion, F# way (Unquote)
Unquote uses F# quoted expressions to express assertions
and produce detailed error messages
Isolation, C# way
• Moq
• Rhino Mocks
• Typemock Isolator
• NMock
• NUnit.Mocks
• Microsoft Fakes / Moles
• NSubstitute
• FakeItEasy
Isolation, C# example
Isolation, C# example
Isolation, C# example
Isolation, F# way
Unit Testing with F#
• Less mocks
(more stubs)
• Simpler assertions
(unquote)
• No test induced damage
(functions as interfaces)
DEMO
Links
• Unquote - https://code.google.com/p/unquote/
• Railway Oriented Programming -
http://fsharpforfunandprofit.com/posts/recipe-part2/
• Mark Seeman’s blog - http://blog.ploeh.dk/
• Mark Seeman’s Pluralsight courses -
http://www.pluralsight.com/author/mark-seemann
(highly recommended!)