1
好吧,我承认,这是一个独特的案例。当我们构建我们的应用程序时,我们使用make,所以我将测试包含在src下的测试文件夹中。然后在与我们的发行版文件夹相同的级别上,我们创建了一个包含我们所有源文件和测试源文件的单元测试文件夹。GoogleTest CMake不承认TEST_F:就像它不承认GTest的东西
但我的IDE是CLion,它使用CMake。在我的CMakeLists.txt文件中,我包括:
enable_testing()
find_package(GTest REQUIRED)
include_directories(${GTEST_INCLUDE_DIRS})
add_executable(TestProject ${SOURCE_FILES})
target_link_libraries(TestProject ${GTEST_BOTH_LIBRARIES})
我正在创建我的第一个测试夹具。下面是代码:
#include "OPProperties.h"
#include "gtest/gtest.h"
namespace {
// The fixture for testing class OPPropertiesTestTest.
class OPPropertiesTestTest : public ::testing::Test {
protected:
// You can remove any or all of the following functions if its body
// is empty.
OPPropertiesTestTest() {
// You can do set-up work for each test here.
}
virtual ~OPPropertiesTestTest() {
// You can do clean-up work that doesn't throw exceptions here.
}
// If the constructor and destructor are not enough for setting up
// and cleaning up each test, you can define the following methods:
virtual void SetUp() {
// Code here will be called immediately after the constructor (right
// before each test).
}
virtual void TearDown() {
// Code here will be called immediately after each test (right
// before the destructor).
}
// Objects declared here can be used by all tests in the test case for OPPropertiesTestTest.
};
TEST_F(OPPropertiesTestTest, ThisTestWillFail) {
EXPECT_EQ(0, 2);
}
} // namespace
int main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
这里是一个图像采集:
通知我TEST_F函数的语法检查错误。当我开始键入TEST_F代码完成时,试图找到一个升压测试功能。
有人能告诉我还有什么需要添加到CMakeLists.txt文件或我没有做什么GTest功能不被识别?
呵呵,我对CMake的'find_package'完全没有专业知识。事实上,我很失败地用'GTest'来使用它。但是在所有的测试用例源代码看起来都不错。 _“注意语法检查器错误”_你有这个代码的实际编译错误吗? GoogleTest和GoogleMock使用了一些_esoteric_模板技术,这些技巧非常适合混淆数个IDE的索引器和智能感知代码检查器(例如,在使用Eclipse CDT Luna处理测试案例时,我经常遇到后者。 –