0

I've got a VS2015 C++ project and thousands tests written using googletest/googlemock and packed into a single executable file.

How can I know which tests and test cases cover a particular function?

For example, my test pack consists of TestSuite0, TestSuite1, TestSuite2, and each test suite contains a number of tests - Test0, Test2, Test3, etc. All I want to know is which tests cover the MyFunc() function. I want to run all the tests and get something like:

Function MyFunc() is covered by:
TestSuite0.Test3
TestSuite0.Test8
TestSuite1.Test0
TestSuite1.Test2
TestSuite2.Test345

Is there any trick to get this with VS2015 and/or gtest?

Rom098
  • 2,445
  • 4
  • 35
  • 52

2 Answers2

0

Unit-tests tests are often structured same way as the code. You can find out what to run by test and test suite name. And run only certain tests.

How many test go through single function? You can set breakpoint in your function. When breakpoint is hit look into Visual Studio's Call Stack Window to see what test it originates from. You can also have breakpoint writing stack trace and not stopping program. Then you can check the output after whole test suite was run.

Unfortunately there is no such automatic C++ language or Google Test based feature to tell what test are using certain code/line/function. Suppose such think would involve C++ code instrumentation.

Tomas Tintera
  • 787
  • 1
  • 8
  • 19
0

It depends on how particular test cases has written. However --gtest_filter will be handy while deciding individual test cases to be run.

Test Suit are usually associated with performing test on Class, However individual test cases are associated with particular member function(MyFunc()). There are multiple individual test cases which validate different execution path of same member func (MyFunc()).

So considering above , You may find multiple test cases within Test Suit.

TestSuite1.MyFunc
TestSuite1.MyFuncInvalidArgument
TestSuite1.MyFuncPerformanceCheck

while running this with gtest you can use

--gtest_filter=TestSuite1.MyFun*

If the function has spread across several testSuit you can add this filter too.

--gtest_filter=TestSuite1.MyFun*:TestSuite0.MyFunc*

If existing test cases and test suit doesn't follow this recommended pattern,Then you have to search across test suit and identify individual test case and use them with --gtest_filter

How to specify multiple exclusion filters in --gtest_filter?

sameer chaudhari
  • 928
  • 7
  • 14