1 Piling
1.1. Writing source code and test code
1.2. Writing pile functions
[parasoft]-[display view]-[pile function]
[Select original (function)]-[right-click to create user pile function ...]
Writing User pile functions
2 Source code
#include <stdio.h>
int add (int a,int b)
{
return a+b;
}
int compare (int a,int b)
{
if (a>=b)
Return Add (A, b);
Else
Return Add (A, b);
}
void Main ()
{
int a=10,b=5;
int C=compare (A, b);
printf ("%d", c);
scanf ("%c", &c);
}
3 Test Code
#include "Cpptest.h"
Cpptest_context ("cpptest/cpptest/source file/cpptest.cpp");
Cpptest_test_suite_included_to ("cpptest/cpptest/source file/cpptest.cpp");
Class Testsuite2:public Cpptest_testsuite
{
Public
Cpptest_test_suite (TESTSUITE2);
Cpptest_test (test_compare_1);
Cpptest_test (test_compare_2);
Cpptest_test_suite_end ();
void Test_compare_1 ();
void Test_compare_2 ();
};
Cpptest_test_suite_registration (TESTSUITE2);
void Testsuite2::test_compare_1 ()
{
int a=10,b=6;
int C=compare (A, b);
Cpptest_assert_integer_equal (4,C);
}
void Testsuite2::test_compare_2 ()
{
int a=10,b=6;
int C=compare (A, b);
Cpptest_assert_integer_equal (1,C);
}
4-Pile Code
#include "Cpptest.h"
int add (int a, int b);
int Cpptest_stub_add (int a, int b)
{
Based on different test cases, such as test_compare_1,test_compare_2
Different branches of pile function are executed separately, and a pile function is implemented to return different values.
if (strcmp ("Test_compare_1", Cpptest_getcurrenttestcasename ()) ==0)
{
return 4;
}
else if (strcmp ("test_compare_2", Cpptest_getcurrenttestcasename ()) ==0)
{
return 1;
}
}
C++test Piling