Download - Fharp Unit Testing

Transcript
Page 1: Fharp Unit Testing

Unit Testing with F#

Sugak Alexandr

Page 2: Fharp Unit Testing

Unit Testing

Page 3: Fharp 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

Page 4: Fharp Unit Testing

Assertion, C# way (MSTest)

Page 5: Fharp Unit Testing

Structural Equality

Page 6: Fharp Unit Testing

F# has Structural Equality for:

• Records

• Discriminated Unions

• Arrays

• Lists

Page 7: Fharp Unit Testing

Assertion, F# way (Unquote)

Unquote uses F# quoted expressions to express assertions

and produce detailed error messages

Page 8: Fharp Unit Testing

Isolation, C# way

• Moq

• Rhino Mocks

• Typemock Isolator

• NMock

• NUnit.Mocks

• Microsoft Fakes / Moles

• NSubstitute

• FakeItEasy

Page 9: Fharp Unit Testing

Isolation, C# example

Page 10: Fharp Unit Testing

Isolation, C# example

Page 11: Fharp Unit Testing

Isolation, C# example

Page 12: Fharp Unit Testing

Isolation, F# way

Page 13: Fharp Unit Testing

Unit Testing with F#

• Less mocks

(more stubs)

• Simpler assertions

(unquote)

• No test induced damage

(functions as interfaces)

Page 14: Fharp Unit Testing

DEMO


Top Related