Indicating Pass/Fail in a Test Method
Jump to navigation
Jump to search
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);
srASSERT_EQ(sum, 6);
}
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;
}