I'm not sure about this one.  It looks like the embedding for the test
fixture needs (the enumeration data) needs to provide a lot of logic.
There are some particular test patterns I'd like to abstract:

1. What happens when calling Current before MoveNext.
2. What happens when calling Current after MoveNext returns true.
3. What happens when calling Current after MoveNext returns false.
4. What happens when calling Current after Reset.
5. What happens when calling MoveNext after Reset.

I can easily cook up the pattern the test input must satisfy in some
kind of Tester class.  I can also verify the results quite easily
because the specification of IEnumerable is known.  IMHO pushing
verification down to a class like IEnumerationData partly defeats the
purpose of the Tester.  In particular, the caller would have to cook up
several IEnumerationData's with different implementations of
MakeANewTestSubject to ensure that all of the interesting cases get
covered.  It's also coupled to the particular sequence of requests
issued by the Tester.

Ideally I want to be able to extend the Tester to cover new scenarios
without having to modify its inputs in any way.

It might be helpful to think of a related testing approach.  We could
annotate a test method with the expected input and output domains of a
given operation.  For stateful objects we could annotate the various
transitions among states.  Then we have MbUnit go ahead and cook up test
input based on the annotations and verify the results.

So an interesting way to write a test fixture would be to describe the
state machine of the object under test...

Jeff. 

-----Original Message-----
From: [email protected] [mailto:[EMAIL PROTECTED]
On Behalf Of Jay Flowers
Sent: Friday, September 15, 2006 4:41 AM
To: [email protected]
Subject: MbUnit Re: TypeFixture on steroids was RE: MbUnit Re: Research:
Using LSP to ease testing


For my article/post I am going to to use the following for the complex
example:

public interface IEnumerationData
{
        IEnumerator MakeANewTestSubject();
        void VerifyMoveNextValue(bool actual);
        void VerifyCurrentValue(object actual);
        void VerifyEndOfMovingForward();
}

public class ArrayData : IEnumerationData {
        private String[] _TestSubject;
        public IEnumerator MakeANewTestSubject()
        {
                _TestSubject = new String[3] {"one", "two", "three"};
                return _TestSubject.GetEnumerator();
        }

        private bool[] _MoveNextExpectations;
        private bool[] MoveNextExpectations
        {
                get
                {
                        if (_MoveNextExpectations == null)
                                _MoveNextExpectations = new bool[4] {
true, true, true, false };
                        return _MoveNextExpectations;
                }
        }

        private int _MoveNextCount;
        private int MoveNextCount
        {
                get
                {
                        return _MoveNextCount;
                }
                set
                {
                        _MoveNextCount = value;
                }
        }

        public void VerifyMoveNextValue(bool actual)
        {
        
Assert.AreEqual(this.MoveNextExpectations[this.MoveNextCount], actual);
                this.MoveNextCount++;
        }

        public void VerifyCurrentValue(object actual)
        {
                Assert.AreEqual(this._TestSubject[this.MoveNextCount -
1], actual);
        }

        public void VerifyEndOfMovingForward()
        {
                Assert.AreEqual(this.MoveNextCount, 4, "Expected
MoveNext to have been called 4 times");
        }
}

[TypeFixture(typeof(IEnumerationData))]
public class IEnumerableTester
{
        [Provider(typeof(IEnumerationData))]
        public IEnumerationData ProvideArrayData()
        {
                return new ArrayData();
        }

        [Test]
        [ExpectedException(typeof(InvalidOperationException))]
        public void TestInitialCurrentValue(IEnumerationData testData)
        {
                object InitalValue = null;
                InitalValue = testData.MakeANewTestSubject().Current;
        }

        [Test]
        public void TestMovingForward(IEnumerationData testData)
        {
                object Value = null;
                bool HasValue = false;
                IEnumerator TestSubject =
testData.MakeANewTestSubject();

                HasValue = TestSubject.MoveNext();
                testData.VerifyMoveNextValue(HasValue);

                while (HasValue)
                {
                        Value = TestSubject.Current;
                        testData.VerifyCurrentValue(Value);

                        HasValue = TestSubject.MoveNext();
                        testData.VerifyMoveNextValue(HasValue);
                }

                testData.VerifyEndOfMovingForward();
        }
}


--
Jay Flowers
----------------------------------------------------------------------
http://jayflowers.com
---------------------------------------------------------------------



--~--~---------~--~----~------------~-------~--~----~
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