googletest

How to run specific test cases in GoogleTest

隐身守侯 提交于 2019-11-27 16:58:54
I am trying to write a function/method for my project, which will ask to user which all test cases are you going to run? It looks like below..., Test_Cases_1 |_TestNo1 |_TestNo2....so on Test_Cases_2 |_TestNo1 |_TestNo2....so on .... ....so on Test_Cases_N |_TestNo1 |_TestNo2....so on So, now the challenge is while running the project it should prompt me what all test cases you would like to execute? If I select Test_Cases_1 and Test_Cases_N . Then it should execute these two test cases and should exclude all other from Test_Cases_2 to .... . In result window also I would like to see the

How to test c++ template class with multiple template parameters using gtest?

五迷三道 提交于 2019-11-27 16:31:13
问题 I want to test a template class with gtest. I read about TYPED_TESTs in gtest manual and looked at the official example (samples\sample6_unittest.cc) they reference. This template from the example has only one template parameter. But, my code has two template parameters, how can I test it? I have the following code: // two element type template <typename E, typename F> class QueueNew { public: QueueNew() {} void Enqueue(const E& element) {} E* Dequeue() {} F size() const { return (F)123; } };

CPack: Exclude INSTALL commands from subdirectory (googletest directory)

戏子无情 提交于 2019-11-27 16:11:26
I'm using CMake for a project and googletest for my test cases. Looking around the internet, it seems to be common practise to just copy the googletest source into a subfolder of your repository and include it with "add_subdirectory(googletest)". I did that. Now I'm using CPack to generate debian packages for my project. Unfortunately, the packages generated by CPack install googletest alongside with my project. This is of course not what I want. Looking in the googletest directory, I found some INSTALL cmake commands there, so it is clear, why it happens. The question is now - how can I avoid

Why is GoogleMock leaking my shared_ptr?

喜欢而已 提交于 2019-11-27 15:36:50
问题 I use GoogleMock/GoogleTest for testing, and I'm seeing some strange behavior when a matcher has a shared_ptr to a mock as a parameter, and EXPECT is called on the same shared_ptr. The offending piece of code: #include <gmock/gmock.h> #include <gtest/gtest.h> #include <boost/shared_ptr.hpp> #include <boost/make_shared.hpp> using namespace boost; using namespace testing; struct MyParameter { virtual ~MyParameter() {} virtual void myMethod() = 0; }; struct MyParameterMock : public MyParameter {

linking error when building Google test on mac (commandline)

偶尔善良 提交于 2019-11-27 14:50:10
问题 I am currently trying to build some test code that uses Google C++ Test framework but I keep getting an error stating ld: warning: in /usr/local/lib/libgtest.dylib, file was built for unsupported file format which is not the architecture being linked (i386) I have tried to make the issue as simple as possible: I have a main function cmtest.cc #include <gtest/gtest.h> /** Main entry point */ int main(int argc, char**argv, char**envArg) { testing::InitGoogleTest(&argc, argv); return(RUN_ALL

error during making GTest

老子叫甜甜 提交于 2019-11-27 14:23:17
问题 I was trying to set up GTest environment on my Ubuntu machine. but while making the GTest to get the library, i get the following error... som@som-VPCEH25EN:~/Workspace/CPP/gtest-1.6.0/make$ make g++ -I../include -g -Wall -Wextra -lpthread sample1.o sample1_unittest.o gtest_main.a -o sample1_unittest gtest_main.a(gtest-all.o): In function `~ThreadLocal': /home/som/Workspace/CPP/gtest-1.6.0/make/../include/gtest/internal/gtest-port.h:1336: undefined reference to `pthread_getspecific' /home/som

Android NDK with Google Test

送分小仙女□ 提交于 2019-11-27 14:01:08
问题 I'm trying to use GoogleTest on Android Studio. According to what I understood, the latest version of NDK has the gtest included. I did not find a clear guide how to do it. I followed this document: So, I opened a new project, created jni folder and the following files (inside the files I wrote exactly what the document): But it does not recognize the #include gtest/gtest.h In addition, how to run the adb at the end? I created an android.mk file but where should I call it? 回答1: If you choose

CMake cannot find GoogleTest required library in Ubuntu

白昼怎懂夜的黑 提交于 2019-11-27 13:50:52
问题 Similar issue here. This is my CMakeLists.txt: cmake_minimum_required(VERSION 2.6) # Locate GTest find_package(GTest REQUIRED) include_directories(${GTEST_INCLUDE_DIRS}) # Add test cpp file add_executable(foo foo.cpp) # Link test executable against gtest & gtest_main target_link_libraries(foo ${GTEST_LIBRARIES} ${GTEST_MAIN_LIBRARIES} pthread) And my foo.cpp: #include <gtest/gtest.h> TEST(sample_test_case, sample_test) { EXPECT_EQ(1, 1); } int main(int argc, char **argv) { testing:

How to test an EXE with Google Test?

会有一股神秘感。 提交于 2019-11-27 13:43:11
I have a C++ project in Visual Studio, and have added another project exclusively for testing. Both of these projects are EXEs (console apps). So how do I use the first project inside the second? Just to clarify, the question here would be somewhat self-evident if the first project was a library that one could simply include in the second project but, being an EXE, this is where the problem lies. Per your comments, you have a C++ console application ( MyApp) for which you have developed some application-specific classes that you want to unit-test with googletest in Visual Studio. How? As you

How to capture stdout/stderr with googletest?

大憨熊 提交于 2019-11-27 09:58:17
问题 Is it possible to capture the stdout and stderr when using the googletest framework? For example, I would like to call a function that writes errors to the console (stderr). Now, when calling the function in the tests, I want to assert that no output appears there. Or, maybe I want to test the error behaviour and want to assert that a certain string gets printed when I (deliberately) produce an error. 回答1: I have used this snippet before to redirect cout calls to a stringstream when testing