0

I am following this tutorial, but I dont entirely understand how the TEST functions are executed

https://www.bogotobogo.com/cplusplus/google_unit_test_gtest.php

The example code is here:

#include "gtest/gtest.h"
#include "simplemath.h"

TEST(testMath, myCubeTest)
{
    EXPECT_EQ(1000, cubic(10)); 
}

Does the TEST function get called automatically by the API? What if there are multiple TEST functions?

I have some external code which has multiple TEST functions and I need to call them from another executable outside of GTest. I was able to include the project, but cannot figure out how to call the TEST functions.

Is there any way that I can call TEST manually from another piece of code?

I see that TEST is defined as GTEST_TEST in gtest.h But I don't see where GTEST_TEST is defined. Where is the main function? Is it somewhere in gtest api?

Thanks,

Mi Po
  • 1,123
  • 2
  • 12
  • 21

1 Answers1

0

You don't need to write main. From docs:

Most users should not need to write their own main function and instead link with gtest_main (as opposed to with gtest), which defines a suitable entry point.

But you can filter, see this answer.

int main(int argc, char **argv) {
    ::testing::InitGoogleTest(&argc, argv);
    ::testing::GTEST_FLAG(filter) = "Test_Cases1*";
    return RUN_ALL_TESTS();
}

You'll get more options on that answer.

Manuel
  • 2,526
  • 1
  • 13
  • 17