googletest

Passing a typename and string to parameterized test using google test

痞子三分冷 提交于 2019-12-12 08:52:55
问题 Is there a way of passing both a type and a string to a parametrized test using google's test. I would like to do: template <typename T> class RawTypesTest : public ::testing::TestWithParam<const char * type> { protected: virtual void SetUp() { message = type; } }; TEST_P(RawTypesTest, Foo) { ASSERT_STREQ(message, type); ParamType * data = ..; ... } Thanks in advance 回答1: Value parameterized tests won't work for passing type information; you can only do that with typed or type parameterized

Make protected inner class public

拟墨画扇 提交于 2019-12-12 05:31:03
问题 I have the following class: class A { protected: class InnerA {}; }; Now I need to gain access to InnerA class in the tests. Theoretically I could create a test class derived from A and make some parts of A class public. I could do this with fields of course, but not with inner classes. Is there a way to see the protected InnerA class from outside of A class hierarchy (all classes derived from A)? I would like to be able to write: Test(MyTest, InnerATest) { TestA::InnerA x; x.DoSth(); } 回答1:

Actual function call count doesn't match EXPECT_CALL(*mock, display())

与世无争的帅哥 提交于 2019-12-11 18:22:56
问题 I'm calling EXPECT_CALL on a mocked function display() , but it is returning the run time error Actual function call count doesn't match EXPECT_CALL(*mock, display())... output ./GTest_static_example.tst [==========] Running 1 test from 1 test case. [----------] Global test environment set-up. [----------] 1 test from GTest_static_example [ RUN ] GTest_static_example.case1 inside the GTEST_static_class:: display display called from GTest_static_example package/web/webscr/GTest_static_example

How to build and use GoogleTest shared library (.so) using g++ on Linux?

随声附和 提交于 2019-12-11 16:54:30
问题 NOTE it's not a duplicate of this question or this question. How to build Googletest from source using g++ into a shared library (.so)? I tried the steps described in Google Test's document on how to build a shared library, but linking the produced libgtest.so with my test programs didn't work - the linker throws tons of errors like: "gtest-all.cc:(.text+0x19b50): multiple definition of `testing::internal::HasNewFatalFailureHelper::~HasNewFatalFailureHelper()'libgtest.so:gtest-all.cc:(.text

CMake imported target includes non-existent path

只愿长相守 提交于 2019-12-11 16:44:00
问题 I've followed the steps described in Linking against GTest fails, and get this error. CMake Error in src/impl/data_structures/simple_tree/CMakeLists.txt: Imported target "GTest::GTest" includes non-existent path "~/local/include/" Further messages include: in its INTERFACE_INCLUDE_DIRECTORIES. Possible reasons include: * The path was deleted, renamed, or moved to another location. * An install or uninstall procedure did not complete successfully. * The installation package was faulty and

how to test static functions of C using google test

自闭症网瘾萝莉.ら 提交于 2019-12-11 11:55:46
问题 I have a C file contains some static functions, how to use google test to test those static function? header file: test.h int accessData(); source file: test.c static int value; static int getData() { return value; } int accessData() { if(value != 0) { return getData(); } return 0; } static function is called by global function, but how to test those static function using google test? 回答1: One way to achieve this is to #include the C source file into your test source. Then, the static

Google Tests ValuesIn with a global vector

大城市里の小女人 提交于 2019-12-11 10:29:56
问题 I'm trying to run a bunch of google tests based off configuration files in a directory. This way I can just add a new file and run the tests without having to add it to my parametrized test and recompile. Here is my code: typedef std::pair<QString, int> TestParam; QString generatedLogic; std::vector<TestParam> badExpressionTests; class LogicBuilderTest : public ::testing::TestWithParam<TestParam> {}; GTEST_API_ int main(int argc, char **argv) { testing::InitGoogleTest(&argc, argv); :

Can't get google test to work

孤街浪徒 提交于 2019-12-11 09:48:59
问题 #include "gtest/gtest.h" TEST(BattleUnitTest, CountryReturnsProperName) { EXPECT_EQ(1, 1); } int main(int argc, char* argv[]) { testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } I can't seem to get google test to work. I ran Nuget package manager to get gtest. It keeps giving me these errors: Severity Code Description Project File Line Error LNK2019 unresolved external symbol "bool __cdecl testing::internal::IsTrue(bool)" (?IsTrue@internal@testing@@YA_N_N@Z) referenced in

Base method called in Google Test

纵然是瞬间 提交于 2019-12-11 09:06:18
问题 I am trying to write a binary tree implementation in C++ and I'm testing it using Google Test. In order to test the in-order traversal I am sub-classing the BTree class so that I can override the visit() method so that I can output to a string instead of to the console. The problem is that I want to use the existing logic to insert new nodes to the tree and it's inserting the base class instead of the derived class even though I am passing a pointer to a derived object to the insert() method.

How can I use Google Test to call specific test functions at specific places in the main() function?

妖精的绣舞 提交于 2019-12-11 08:12:37
问题 I am using TDD and Google Test for a project that involves numerical simulations. The state of the data gets changed within a loop in the main function, but there are requirements that need to be fulfilled after each change. If all requirements are fulfilled for a test case, the acceptance test passed: while(simulation) modify simulation data FIRST_TEST() some other simulation operations SECOND_TEST() The GTest primer states that usually RUN_ALL_TESTS() is called. The Advanced Guide shows how