Loading presentation...

Present Remotely

Send the link below via email or IM

Copy

Present to your audience

Start remote presentation

  • Invited audience members will follow you as you navigate and present
  • People invited to a presentation do not need a Prezi account
  • This link expires 10 minutes after you close the presentation
  • A maximum of 30 users can follow your presentation
  • Learn more about this feature in our knowledge base article

Do you really want to delete this prezi?

Neither you, nor the coeditors you shared it with will be able to recover it again.

DeleteCancel

Make your likes visible on Facebook?

Connect your Facebook account to Prezi and let your likes appear on your timeline.
You can change this under Settings & Account at any time.

No, thanks

New FsCheck API

A tour of the new and improved FsCheck API (v0.7, I guess...)
by

Kurt Schelfthout

on 1 June 2010

Comments (0)

Please log in to add your comment.

Report abuse

Transcript of New FsCheck API

Gen Arb Prop Helper functions to build Property instances
aka properties
aka parametrized unit tests of the form <args> -> 'Testable -> Property 'Testable is just a generic type FsCheck interprets the type at runtime - is 'Testable:
unit: test succeeds if accessing the value does not throw
bool: test succeeds if accessing the value does not throw and is true
Property: test succeeds if the Property succeeds
fun arg -> 'Testable: find generator for arg based on its type - convert 'Testable to property as above
Lazy<'Testable>: force the value - convert 'Testable to Property as above Traditional unit test = method without arguments
arrange: set up arguments to method calls
act: call the methods
assert: check the results FsCheck test = function with arguments
arranged: FsCheck generates random arguments
act: call the functions under test
assert: check the results No need to come up with examples
Tests are more general - more like specifications
They're called properties. Transform anything that is testable into a Property - the type of things that can be tested Helper functions to build Arbitrary<'a> types
to generate and shrink instances of type 'a A lap around
FsCheck Generator: Gen<'a> + Shrinker: 'a -> Seq<'a> Helper functions to build Gen<'a> types
which generate random values of type 'a Running tests Focus of v0.7 Usability Consistency Discoverability Easy to diagnose problems follows FSharp.Core patterns Integration Better error messages Works well with intellisense Documentation The moving parts generate random values shrink values if test fails gather intermediate results collect statistics write properties to test Properties are universally quantified over their arguments:
"for all lists xs: the reverse of the reverse of a list is the original list" No asserts: test is a function that returns true or false Throwing an exception is considered failing the test Although properties are universially quantified,
exhaustive testing is computationally impossible So we generate a number of random values FsCheck can by default generate random
primitive types
rccord types
union types
function types And provides utility functions to easily build your own custom generators useful to find out which values were generated confirm that generated values are appropriate crucial to check that the system under test is adequately tested although properties are just functions that return booleans,
for complex properties it is useful to gather intermediate results helps with diagnosing test failures generated random values can become very large
e.g. list of tens or hundreds of elements if a property fails, it can be hard to find out why, if the counter-example is large so when a property fails for a particular randomly generated value,
FsCheck will try to make it smaller
e.g. by leaving elements out of the list and checking that the property still fails New API
3 type and module pairs Check Config has static members to do various kinds of checking:
given a type, will check all the public methods on the type as properties
given a function, will check the function
given a MethodInfo, will check the function or method
A record type to set various properties of testing:
Number of (passing) tests
Number of rejected tests before FsCheck gives up
Begin- and endsize
Functions to customize output and test runner

has static members with the predefined configurations:
Quick, Default
Verbose: prints every generated argument
Augment it with your own configurations
FsCheck prints these when a test fails Sorry for the rename-pain...
I hope you like the new API! Feedback?
http://fscheck.codeplex.com
http://fortysix-and-two.blogspot.com
kurt dot schelfthout at gmail dot com
Full transcript