I am using CPPUNIT to do unit testing for my C++ program
For non-void functions , assuming the function add() exist
int add(int num1 , int num2)
{
return num1+num2;
}
I could do unit testing like this
void newtestclass::add()
{
int result = add(2,3);
CPP_ASSERT(result == 5 );
}
I encounter problem when i try to do unit testing for non-void functions
void printmenu()
{
cout<<"1) Option A"
<<endl
<<"2) Option B";
}
How do i do unit testing for such functions to ensure 100% code coverage
I also encounter problems doing unit testing for functions nested in other functions
void menu_select(char x)
{
if ( x == 'a')
{
add();
}
else if ( x == 'b' )
{
subtract();
}
}
void menu()
{
char choice;
cout<<"a) Add "
<<endl
<<"b) Subtract";
cin>>choice;
menu_select(choice);
}
How do i do unit testing for such functions to ensure 100% code coverage