googletest

Google Test: error LNK2019: unresolved external symbol with Visual Studio 2013

白昼怎懂夜的黑 提交于 2019-12-10 09:37:41
问题 I'm trying to get my first ever unit test with Google Test framework + Visual Studio 2013.However I'm hitting the below error and can't understand why. 1>------ Build started: Project: FirstGoogleTest, Configuration: Debug Win32 ------ 2>------ Build started: Project: googleTest, Configuration: Debug Win32 ------ 1> MyMultiplier.cpp 2> gtest_main.cc 1> main.cpp 1> Generating Code... 2> gtest-all.cc 1> FirstGoogleTest.vcxproj -> D:_Vault\Workspaces\UnitTestLearning\FirstGoogleTest\Debug

find external test file for unit test by relative path c++ cmake guest

僤鯓⒐⒋嵵緔 提交于 2019-12-10 02:16:06
问题 What would be the proper way to access an external test file for the unit test of a c++ project? I am using CMake and Gtest. This is a sample of the directory structure. Project -src -test (unit tests here) -test-data (data file here) Thanks! 回答1: Pass the file name to gtest arguments: add_executable(foo ...) enable_testing() add_test(FooTest foo "${CMAKE_CURRENT_LIST_DIR}/data/input.file") get the parameter after gtest parse input: int main(int argc, char** argv) { ::testing::InitGoogleTest(

What's the way to access argc and argv inside of a test case in Google Test framework?

爷,独闯天下 提交于 2019-12-10 02:15:53
问题 I’m using Google Test to test my C++ project. Some cases, however, require access to argc and argv to load the required data. In the main() method, when initializing, argc and argv are passed to the constructor of testing. testing::InitGoogleTest(&argc, argv); How can I access them later in a test? TEST(SomeClass, myTest) { // Here I would need to have access to argc and argv } 回答1: I don't know google's test framework, so there might be a better way to do this, but this should do: //--------

Mocking an entire library

青春壹個敷衍的年華 提交于 2019-12-09 18:27:24
问题 I'm developing code that uses boost::asio . To test it, I need to mock a set of classes from this library. I'm using Google Mock, which allows for mocking virtual methods. The usual (and tedious) process would be to write an interface for each of the classes I need to use. On the other hand, the Google Mock Cookbook describes an alternative when it comes to mocking non-virtual methods: using templates. The problem in my case is that I might need to mock several classes at the same time (so

_stricmp with mingw and c++0x not existent?

对着背影说爱祢 提交于 2019-12-09 14:05:54
问题 I'm currently trying to use googletest with MinGW and -std=c++0x but it complains that _stricmp is not declared in this scope which it doesn't when I do not use -std=c++0x . I have no idea what _stricmp is, I just found out that it is defined in cstring/string.h , so why is it gone in C++0x? 回答1: The -std=c++0x option causes g++ to go into 'strict ANSI' mode so it doesn't declare non-standard functions (and _stricmp() is non-standard - it's just a version of strcmp() that's case-insensitive).

Unit test from google test no longer found after adding header with boost::filesystem

我的梦境 提交于 2019-12-08 21:56:13
问题 I have a unittest project which using google test framework and my tests was working fine. However now I added boost::filesystem header like #include <boost/filesytem.hpp> and after that my project linking and compiling fine, however no tests found at all and when I run tests it's give me - Process finished with exit code -1073741515 (0xC0000135) Empty test suite. Like if I have this code: #include <gtest/gtest.h> TEST(Test, Test1){ ASSERT_FALSE(true); } it works perfectly fine and find

googlemock - mock a method that returns a complex datatyp

岁酱吖の 提交于 2019-12-08 19:12:11
问题 I want to mock a method that returns a complex datatyp class aClass { public: virtual const QMap<QString, QString> aMethod() const; } class MockaClass : public aClass { public: MOCK_CONST_METHOD0(aMethod, const QMap<QString, QString>()); } This code does not compile: "macro "MOCK_CONST_METHOD0" passed 3 arguments, but takes just 2" I think that the googlemock macro does not understand QMap and interpret the comma as parameter separator. Is there a way to tell googlemock that QMap is the

Mocking Parametrized Constructor using Gmock

喜欢而已 提交于 2019-12-08 17:19:01
问题 I have class to be mocked but it is not having default constructor. I cannot change the source code. So is there any way to mock a parametrized constructor using Gmock 回答1: Yes there is. Just let your Mock's constructor call the mocked class' constructor with the right arguments: class base_class { public: base_class(int, int) {} virtual int foo(int); }; class base_mock : public base_class { public: base_mock() : base_class(23, 42) {} MOCK_METHOD1(foo, int(int)); }; or even class base_mock :

Benchmarking with googletest?

﹥>﹥吖頭↗ 提交于 2019-12-08 14:52:11
问题 Background (skip to Question below if not interested) I have a simulator that runs through three states: Single threaded startup (I/O ok) Multi-threaded in-memory CPU-bound simulation stage (I/O not ok) Post-simulation, post-join single threaded stage (I/O ok) What the heck! During standard testing, CPU usage dropped from 100% down to 20% , and the total run took about 30 times longer than normal (130secs vs 4.2secs). When Callgrind revealed nothing suspicious, my head buzzed as I was on the

Unit test a variable for both true and false

≯℡__Kan透↙ 提交于 2019-12-08 05:27:12
问题 I'm working on a C++ production code here with googletest/googlemock. I've stumble upon this idea when working with one of the function in A.cpp: bool A::process_(false); bool A::process() { if ( !process_ ){ process_ = true; } return process_; } where the header contains: protected: static bool process_; public: static bool process(); I am stuck in a way that I can only test the function for an expected output of true or an input of false like so: TEST(ATest, processVal){ A a; EXPECT_TRUE(a