acidtests inheritance

0 views
Skip to first unread message

kilfour

unread,
Dec 15, 2009, 8:54:47 AM12/15/09
to QuickNet
this allows one to group specifications in subclasses of the 'Context'
class (containing the transitions and state).

turning something like this :

public class AcidTestInheritenceSpike : AcidTest
{
public AcidTestInheritenceSpike() : base(100, 10) { }

public class GetValue : MetaTransition<Sut, int>
{
public GetValue()
{
Generator = new GeneratorFor<Sut>();
Execute = i => i.Value;
}
}

[SpecFor(typeof (GetValue))]
public Spec IfNegative(Sut input, int output)
{
return
new Spec(() => Ensure.True(output < 0))
.If(() => input.IsNegative);
}

[SpecFor(typeof(GetValue))]
public Spec IfPositive(Sut input, int output)
{
return
new Spec(() => Ensure.True(output > 0))
.If(() => !input.IsNegative);
}
}

into :
public class AcidTestInheritenceSpike : AcidTest
{
public AcidTestInheritenceSpike() : base(100, 10) { }

public class GetValue : MetaTransition<Sut, int>
{
public GetValue()
{
Generator = new GeneratorFor<Sut>();
Execute = i => i.Value;
}
}
}

public class AcidTestInheritenceSpikeIfNegative :
AcidTestInheritenceSpike
{
[SpecFor(typeof(GetValue))]
public Spec IfNegative(Sut input, int output)
{
return
new Spec(() => Ensure.True(output <= 0))
.If(() => input.IsNegative);
}
}

public class AcidTestInheritenceSpikeIfPositive :
AcidTestInheritenceSpike
{
[SpecFor(typeof(GetValue))]
public Spec IfPositive(Sut input, int output)
{
return
new Spec(() => Ensure.True(output >= 0))
.If(() => !input.IsNegative);
}
}
later there will be support for 'class-wide' pre- and postconditions
and do-before's


Thoughts ?

Davy Brion

unread,
Dec 15, 2009, 9:27:05 AM12/15/09
to quic...@googlegroups.com
i like it, though i would probably go for a subclass containing most of the specs instead of a subclass with one spec each

Mark Meyers

unread,
Dec 15, 2009, 10:07:19 AM12/15/09
to quic...@googlegroups.com
That would indeed by the first way of using it.
This feature is implemented in the trunk earlier today.

Grouping of specs can be usefull if you have lot's of them though.

inside one class you could have :

[[Precondition(typeof(GetValue))]]
public bool IsNegative(Sut input, int output)
{
    return input.IsNegative
}

and any spec in that class would have this precondition added to it's own. That way you don't have to repeat it in every spec.
I can imagine, well, ... I'm looking at it really ;-), a situation where one of the postconditions of most of the specs is 'the operation didn't throw an exception'

I was looking for a way to avoid repeating that all the time and this is what I came up with.

I could then have one class containing all these specs that don't throw an exception, and another one where I deal with what happens when an exception is thrown.

Davy Brion

unread,
Dec 15, 2009, 10:10:02 AM12/15/09
to quic...@googlegroups.com
very nice :)
Reply all
Reply to author
Forward
0 new messages