Clarification on Pre, Post nodes - Unit Testing

LegacyForumLegacyForum Posts: 1,669 ✭✭
edited December 2016 in dotTEST
How to use them
Hi,

I am unable to completely understand the Pre, Post and the OutCome Conditions in .TEST -Unit Testing
I have a method which does not take any parameters nor return any parameters.

The method when called , uses a public variable and performs some manipulations to the variable
so that the value of the public variable is changed inside this method.

Now What is the PreCondition, PostCondition and the OutCome in this case ?

I know that the Outcome is the final return of the method, that is whether the method has executed in sucess or with some exception ?

I was also able to check the PostCondition, Which is the final value of the public variable after the execution of the method.

But i am unable to check the PreCondition value.
the declaration of the public variable is done like this:
CODE
public int var1 = 10;

If i keep the value of Var1 in PreCondition as 0 (Zero) ,
does it mean that the variable Var1 should have the value Zero during the call of the method ?

If so keeping any value (-10 , 0 , 1000 .......) to the value of Var1 in the PreCondition does not give
a " Failed" result for the test case (Scenario).

That is :
I am unable to get the "Fail " resultant on a PreConditon variable value in the TestCase.

Please help me, with an example code if possible :-)
and Sorry for the lengthy post.

Regards
Vijay R

Comments

  • LegacyForumLegacyForum Posts: 1,669 ✭✭
    By setting PreConditions you only set the state of object before running tested method. There is no checking prcess in this place.
    So in your example if you set var1 to 0, this will only mean that before running your method this public var1 has value 0.

    In PostConditions you can assert the state of object after executing tested method.
    Example: if you set in PostConditions that public var1 must be 2 and after run of tested method it will have value 33, the test fill indicate FAIL state.

    In Outcome you can specify an expected result of tested method. For method that returns void you can only choose if you are expecting normal return or some exception should raised during run.

    I hope this will help you.
Sign In or Register to comment.