C++test Piling

Source: Internet
Author: User
Tags strcmp

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.