简体   繁体   中英

Google Test test name confusion

I'm really confused by what SquareTest and PosZeroNeg is representing in this example. I would expect that they are strings being passed into a function, but they aren't? I'm new to c++ so I'm not even sure what to look up since I've never seen anything like this. CLion is showing those "variable string" things as valid c++. Can someone explain what this is?

#include "gtest/gtest.h"
#include "Particle.h"

TEST (SquareTest /*test suite name*/, PosZeroNeg /*test name*/) {
    EXPECT_EQ (9.0, (3.0*2.0)); // fail, test continues
    ASSERT_EQ (0.0, (0.0));     // success
    ASSERT_EQ (9, (3)*(-3.0));  // fail, test interrupts
    ASSERT_EQ (-9, (-3)*(-3.0));// not executed due to the previous assert
}

TEST is a macro with two arguments, the macro produces the test case SquareTest.PosZeroNeg . It may depend on an implementation, but in this particular example this days, SquareTest names a class and PosZeroNeg names a (static) class method, both are generated by the macro, and SquareTest.PosZeroNeg maps these class and method when used. Since the first macro argument is a class name, the second is a method name, they are not strings, but are identifiers, and can not contain quotes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM