views:

275

answers:

4

For example, Reductio (for Java/Scala) and QuickCheck (for Haskell). The kind of framework I'm thinking of would provide "generators" for built-in data types and allow the programmer to define new generators. Then, the programmer would define a test method that asserts some property, taking variables of the appropriate types as parameters. The framework then generates a bunch of random data for the parameters, and runs hundreds of tests of that method.

For example, if I implemented a Vector class, and it had an add() method, I might want to check that my addition commutes. So I would write something like (in pseudocode):

boolean testAddCommutes(Vector v1, Vector v2) {
    return v1.add(v2).equals(v2.add(v1));
}

I could run testAddCommutes() on two particular vectors to see if that addition commutes. But instead of writing a few invocations of testAddCommutes, I write a procedure than generates arbitrary Vectors. Given this, the framework can run testAddCommutes on hundreds of different inputs.

Does this ring a bell for anyone?

A: 

I might not understand you correctly but check this out...

http://www.ayende.com/projects/rhino-mocks.aspx

Adam Driscoll
Mocking is not what's being asked about
Dan Fitch
+1  A: 

I may not understand correctly either, but PEX may be of use to you.

Alan
+1  A: 

There's FsCheck, a port from QuickCheck to F# and thus C#, although most of the doc seems to be for f#. I've been exploring the ideas myself aswell. see : http://kilfour.wordpress.com/2009/08/02/testing-tool-tour-quicknet-preview/

kilfour
A: 

to elaborate on my previous remark, the QN code to test the pseudo-code example would look something like this :

new TestRun(1, 1000)
    .AddTransition(new MetaTransition<Input<Vector, Vector>, Vector>
    {
        Name = "Vector Add ",
        Generator = DoubleVectorGenerator,
        Execute = input => input.paramOne.Add(input.paramTwo)
    }
    .RegisterProperty(
        (input, output) =>
            new QnProperty(
                "Is Communative",
                () => QnAssert.IsTrue(output == input.paramTwo.Add(input.paramOne) )
            )
        )
    )
    .Verify()
    .RethrowLastFailureifAny()
    .ReportPropertiesTested(new ConsoleReporter());

where DoubleVectorGenerator is a userdefined class supplying values of the type Input<Vector, Vector>.

kilfour