Submit and vote on feature ideas.

Welcome to the new Parasoft forums! We hope you will enjoy the site and try out some of the new features, like sharing an idea you may have for one of our products or following a category.

Clarification on Pre, Post nodes - Unit Testing

LegacyForum Posts: 1,664 ✭✭
edited December 2016 in dotTEST
How to use them

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:
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.

Vijay R


  • LegacyForum
    LegacyForum Posts: 1,664 ✭✭
    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.