I have a function-under-test file and a tester file as below:
Line data Source code
1 : #include<iostream>
2 : using namespace std;
3 3 : int GreatestOfThree(int a,int b,int c){
4 3 : if((a>b) && (a>c)){ //for a > b and a>c case
5 1 : return a;
6 : }
7 2 : else if(b>c){ //for b>c case
8 1 : return b;
9 : }
10 : else{
11 1 : return c;
12 : }
13 : return 0;
14 : }
main.cpp
#include "gtest/gtest.h"
#include "main.cpp"
TEST(GreaterTest,AisGreater){
EXPECT_EQ(1,GreatestOfThree(3,1,2));
};
TEST(GreaterTest,BisGreater){
EXPECT_EQ(1,GreatestOfThree(1,3,2));
};
TEST(GreaterTest,CisGreater){
EXPECT_EQ(2,GreatestOfThree(1,2,3));
};
int main(int argc,char**argv)
{
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
main_test.cpp
As you may see in the listing of main.cpp, it has 100% coverage although all tests fail. OK, it is reasonable. All lines are executed. However, I want to include only the lines executed by the passed tests. How can I achieve this?
Thanks.