Indicating Pass/Fail in a Test Method: Difference between revisions
Jump to navigation
Jump to search
(Created page with '==Test Method Return Values== Stride test methods (or free functions in the case of scl_flist test units) must conform to certain criteria. These criteri…') |
|||
Line 69: | Line 69: | ||
{ | { | ||
int sum = DoAdd(3, 3); | int sum = DoAdd(3, 3); | ||
// set the status using a runtime call; much less convenient than | |||
// using the macro, but same result | |||
srTestStatus_e eStatus = (sum == 6) ? srTEST_PASS : srTEST_FAIL; | |||
srTestCaseSetStatus(srTEST_CASE_DEFAULT, | |||
eStatus, | |||
0); | |||
} | |||
void Test3() | |||
{ | |||
// status is not set, so default srTEST_PASS is in force | |||
} | } | ||
</source> | </source> | ||
===integer return=== | ===integer return=== | ||
Revision as of 20:47, 8 February 2012
Test Method Return Values
Stride test methods (or free functions in the case of scl_flist test units) must conform to certain criteria. These criteria allow for several choices in return type from the test method.
Return Type | Description | How Return Value is Interpreted | Default Status |
void | Most common return type | Since there is no return, PASS/FAIL status is set in the body of the method using a
or a runtime call |
|
integer type | Integer types include:
may include signed/unsigned/const qualifiers |
|
|
bool | c++ only |
|
|
Examples
The following example implementations validate the operation of a function named DoAdd() (not shown). Required header file declarations are assumed to be in place.
void return
This is the return type that is most often used as it provides the most convenience.
#include <srtest.h>
void Test1()
{
int sum = DoAdd(2, 2);
// test macro validates condition and sets test status.
// the srEXPECT macros continue
srEXPECT_EQ(sum, 4);
}
void Test2()
{
int sum = DoAdd(3, 3);
// set the status using a runtime call; much less convenient than
// using the macro, but same result
srTestStatus_e eStatus = (sum == 6) ? srTEST_PASS : srTEST_FAIL;
srTestCaseSetStatus(srTEST_CASE_DEFAULT,
eStatus,
0);
}
void Test3()
{
// status is not set, so default srTEST_PASS is in force
}
integer return
bool return
#include <srtest.h>
bool MyTest::Test1()
{
int sum = DoAdd(2, 2);
// return true -> PASS, false -> FAIL
return (sum == 4);
}
bool MyTest::Test2()
{
int sum = DoAdd(3, 3);
//
srEXPECT_EQ(sum, 6);
// return value does not affect test status since the status
// was set explicitly using a test macro above
return true;
}