fharp unit testing

Post on 09-Aug-2015

44 Views

Category:

Software

1 Downloads

Preview:

Click to see full reader

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

top related