There's a refinements we can make to this approach that will support
more cases like IEnumerable:

Instead of using one factory to manufacture instances for all tests,
provide a builder that can manufacture instances that satisfy the
specifications for multiple tests by application of the specified
construction rules.

So you write your tests this way:

interface IEnumerableBuilder<T>
{
    void AddItem(T item);
    IEnumerable<T> GetResult();
}

[Test]
public void TestEmptyEnumeration(Action<IEnumerableBuilder<T>>
builderFactory)
{
    IEnumerableBuilder<T> builder = builderFactory();

    IEnumerable<T> enumerable = builder.GetResult();

    IEnumerator<T> enumerator = enumerable.GetEnumerator();
    Assert.IsNotNull(enumerator, "Enumerator should not be null");

    Assert.Throws(typeof(InvalidOperationException), delegate {
        T element = enumerator.Current;
    }, "Current should throw an exception when run.");

    Assert.IsFalse(enumerator.MoveNext());

    // etc...
}

[Test]
public void TestEnumerationWithOneValue(Action<IEnumerableBuilder<T>>
builderFactory, Action<T> itemFactory)
{
    IEnumerableBuilder<T> builder = builderFactory();
    builder.AddItem(itemFactory());

    IEnumerable<T> enumerable = builder.GetResult();

    // etc...
}


(Incidentally, we should add Assert.Throws to the assertion library!!)

Jeff.

P.S.  I've omitted some details here about where those factories come
from.  I've a very general data binding scheme in mind for MbUnit v3.

-----Original Message-----
From: [email protected] [mailto:[EMAIL PROTECTED]
On Behalf Of Morten Mertner
Sent: Wednesday, September 13, 2006 8:12 AM
To: [email protected]
Subject: MbUnit Re: Research: Using LSP to ease testing


Hi Jay,
> Does this mean that you validated through the interface?  For example 
> with IList you would verify that Add worked by executing Contains?
>   
Yes, there were no explicit references to the implementations inside the
test method, and the results were verified solely using the interface
methods (black box approach). This only works for some interfaces though
- for instance, it's difficult to verify that IEnumerable is correctly
implemented without knowledge of the container (number and ordering of
the items).

The TypeFixture does indeed look like a neat solution for this.

Yours,
Morten




--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"MbUnit.User" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/MbUnitUser
-~----------~----~----~----~------~----~------~--~---

Reply via email to