Hey David,
I'm going to go over some obvious stuff, which you
already know, just for clearity.
I tried to start with something really simple that
represents everything we do when coding, which is
mapping inputs to outputs and storing those inputs and
outputs in tighthy little slots on objects.
So in that example we have two slots.
Let me just define a slot as something that can
contain everything allowed/understood by a computer.
Then we constrained the slots by making them int.
Now they can only contain the subset of all values
allowed that are int.
So now we apply an Operation to the slots and put the
result in a different slot.
So we have a Class that with private int a,b,c
and
an Operation defined in
Java
public int multiply(int a, int b)
return aXb;
It does not really matter what that Operation is, the
only thing we care about is that it correctly maps the
inputs to the outputs.
So lets start with the inputs.
They have already been constrained.
But is it done or is it possible that we need to
constrain variable b further, to satisfy a API
contract definition.
For instance b must be between 100 and 200.
Quick side note(If an EMF model contained all the
variables, a, b, c, etc.) and we needed to place
constraints on a int datatype like this, we could use
an invarient constraint for that.
OK - Back to the logic.
So we constrain b further so that 100 < b < 200.
So now we are wondering whether our method works?
By looking at the constraint for a&b, being that "a"
is an int, and "b" is a further constrained int,
and the mapping the method performs we know all the
possible return values.
We also know all the possible input values.
But we don't want to test every single input to
output...
101X1, 102X1, ...
So which ones do we test?
Let's start with the assuming that were always going
to pass legal values.
So we want to test the type constraint on a and b,
being int.
So lets just assume that on the platform we are
running legal values are
-2222222222222222222 to 2222222222222222222
So we use these two end of range values.
And we test
101 and 199 for b, since that represents b's set of
edge points.
So the combinations we want to test for any
mathematical operations with these two parameters are:
b a
101 X -2222222222222222222
101 X 2222222222222222222
199 X -2222222222222222222
199 X 2222222222222222222
If X works the way it's supposed to, then these tests
should pass.
Also, we test
b a
99 X -2222222222222222222
99 X 2222222222222222222
201 X -2222222222222222222
201 X 2222222222222222222
These should not pass.
Then we assume that all other values are taken care
due to the definition of X.
So were did we get the
99,201,199,101,2222222222222222222,-2222222222222222222
values from.
Lets think of a and b as being datatypes.
b is just a new datatype that can only
have values between 100 and 200.
So a DataType is just meta data defining an allowed
set of values...which is where EMF or Java reflection
comes in. You would use them to analyze the meta data
defined for a type. Then combine that with knowledge
of operators to generate test cases.
Does that make more sense?
Cheers,
- Ole
--- David Saff <
saff@...> wrote:
> Ole,
>
> I'm getting my head around your suggestions. (At
> least) one thing is
> tripping me up:
>
> On 12/31/06, Ole Ersoy <
ole_ersoy@...> wrote:
> > "What does it mean for a method to be 100% unit
> > tested?"
> >
> > For instance suppose there's a method
> >
> > public int multiply(int a, int b)
> >
> > return aXb;
> >
> > Do we unit test this?
>
> Do we write this in the first place? Perhaps
> another example would
> help me more.
>
> David Saff
>
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com