C++ Unit Testing with Google Test Tutorial
Vložit
- čas přidán 31. 08. 2015
- In this tutorial, we take a look at how to perform using testing in C++ using the Google Test framework and ReSharper C++ as the test runner. To find out more about ReSharper C++, please visit:
www.jetbrains.com/resharper-cpp
Author: Dmitri Nesteruk - Věda a technologie
The moment you realized JetBrains didn't "dog food" their C++ IDE on this tutorial
This was an amazing tutorial. Would love to see another one specifically with any nuances in CLion or maybe some for advanced features, but this was great, thank you
7:09 - Great example of parameterized testing in Google Test.
ReSharper seems to be a great extension, the refactoring features are much more advanced comparing to the ones that VS has.
Awesome step-by-step! Thank you very much!
Коротко и по делу. Огромное спасибо автору!
Thank you, very clear and straightforward.
Большое спасибо за проделанную работу!
Really good example of how to use gtest.
Historical note: Before February 2016 *_EQ had a convention of calling it as ASSERT_EQ(expected, actual), so lots of existing code uses this order. Now (2020) *_EQ treats both parameters in the same way. However, when possible, ASSERT_EQ(actual, expected) is preferred. (gtests docs)
Good one. Please do another video for gmock.
only opens some text in the console for me, not in Visual Studio. Did i miss something?
i got error in the INSTANTIATE_TESTCASE_P like function definition not found . what do i do now;
Best way to do this in Linux
very useful for beginners
Could you just explain how did you create the base project, stdafx.h and targetver.h, I can't make this compile, vs can't find the test in test explorer
0:40 Already on it. This is what I want to know. Where did he earn this stuff. How could I have possibly known to do that without this video. This all had to start somewhere.
What is unit test session page in your VS, and where i can find its?
This is ReSharper Unit Test Session tool window (www.jetbrains.com/help/resharper/2016.2/Using_Unit_Test_Sessions.html) If you have ReSharper and/or ReSharper C++ installed it should be available in ReSharper | Windows | Unit Test Sessions.
Thank you!!!!!!!!!!! =*) Спасибочки! Дякую!
Is this present in Clion?
Спасибо за ролик, хороший английский, кстати
I'm not surprised, Dmitri gradated from University of Southampton, UK ))
Does anyone know whats the version of the latest Google test
We need a Clion tutorial please
Is it possible to using googletest and C++ to run automation test on chrome ? Like insert an user and psw in a web page a login automatically ?
Hello Alexander,
thank you for contacting us.
With ReSharper C++ you could run google tests inside Visual Studio: www.jetbrains.com/help/resharper/Unit_Testing_in_CPP.html
Thank you!
why set the field to a pointer (BankAccount*) instead of just the object itself at 4:56?
Without pointer you'll call it by value, but you should call it by reference. hope this one is still actual :D
Why would you use Google Test over asserts or static_asserts?
nice video. Could you make a video about unit testing using also mock files? it will be great
Hello Viorel! Thank you for feedback. We will consider such possibility. Thank you!
As I remember this is in Qt,isn't it? So I don't forget all else...
Please make a video on mocking free functions
could u please give the actual source code of this video
what is the shortcut keyboard to generate the constructor ?? Can anyone help me with that? Thank you
Maybe this will help - www.jetbrains.com/help/resharper/Code_Generation__Type_Constructors.html
When I try to add "account_state {100, 50, 50, true}",I am getting error "expected '(' for function-style cast or type construction". Can any one help me?
Could you share a full sample? Where do you get the error btw? In the IDE or during the compilation?
why not CLion?
+Wenyang Zhao Google Test support in CLion is coming, too!
Link to the code of the video?
Hi, I have such error when running tests: 'Can't run "path" --gtest_list_tests" witch working directory "path": Can't create process'. Maybe someone meet this error?
+Andriy Kuz Could you please download and install the latest ReSharper Release 2016.1 and check if the issue is still present for you? If it won't help could you please send to me some sample solution with this issue to olga.rodygina at jetbrains dot com? Thank you!
can we have an updated version?
We'll definitely plan updating the content. However, except for the UI, not many things changed.
@@JetBrainsTV yes please. Most videos. Including the paid ones are out dated :(
I understand that you're a genius at this stuff, but can you provide a reference for those of us that are new to google test? You know, where every single detail (no matter how small you think it is) is thoroughly explained. Feel free to tell me that I'm a lost cause, if that is indeed the case. Thanks in advance.
Дима а можно по-русски?
0:10 - And if you're not using Visual Studio?
I use QtCreator IDE. You can setup GTest and GMock very quickly:
1) Select "File" > "New Project" > "Other Project" > "Auto Test Project".
2) Next, in drop down list ("Test framework") select "Google Test". Choose the source code folder of Google Test (that you get from GithUb) for example: "E:\Libs\googletest-release-1.10.0". Google Mock will be included too.
Would be better if you move the definitions into header file
Here all fields are public. But how test privatr fields?
Спасибо, но что делать, если мой класс в отдельном .h файле?
How come we aren't using CLion? If C++ was included in the features for Resharper, I would have bought that instead. Sigh.
If anyone is having issue with installation and writing basic test. I have added a guide to installation with some sample code.
github.com/rishabh-agarwal/googleTestDemo
Hope this helps
I wonder how it ran without return value for BankAccount::withdraw
I mean at first, this bool function without a return should cause the program compiling into Error
"if you use visual studio" ... no, I'm using a CMake based project structure with CLion 😅
why not use class instead of struct?
Mostly in C++ use struct if you can to avoid possible memory leak cause struct is a valued type and it was manage by OS that means you dont need to release or delete.
I was thinking exactly the same thing.
@@reysabs I don't know where you're getting your "information" but that is not correct. Structs work exactly like classes except for the default visibility of members.
Im sorry I was referring for creating a Data structure. I used C++ for cross platform mobile development. IOS prefer struct over Class on this matters. I only use Class for methods or anything needs inheritance cause C#, Swift and Java doest support multiple inheritance.
I got a more important question: Why people use inheritance so much. It breaks encapsulation. Use composition as much as possible. People are thought wrongly in the past.
Unclear how to get this "NuGet Packages" =/
lol. test code is 100 times longer/complicated than actual code. it takes more brain to write test code than actual code.
80% (at least for me) of writing code is debugging, and writing test code cuts into that time.
So fast
19 errors at the start already, not compiling
Severity Code Description Project File Line Suppression State
Error C4996 'std::tr1': warning STL4002: The non-Standard std::tr1 namespace and TR1-only machinery are deprecated and will be REMOVED. You can define _SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING to acknowledge that you have received this warning. ExploreGoogleTest \\folderredirect\frrp-data02\ki0v\desktop\work\cpp\exploregoogletest\packages\googletest.1.8.3\build
ative\include\gtest\gtest-printers.h 632
Did you find a solution?
@@abdullahakcam9550 nope
Please use dark mode, my eyes are on fire
hard german accent
I don't understand the point of unit testing anyway, why not just compile your program the normal way and test it ?!
The tests are for future use so when you make changes the tests can verify that the results are still valid.
Imagine you have a program with 10 Millions lines of code written by dozens of different people and you want to add or change a feature or fix a bug. How do you do that and make sure you don't break the rest of the code base. Simple, you use tests.
Tests are for when you go to modify the code. If you didn't write it, or even if you did but some time ago, you can look at it and see that this is what is supposed to happen. Combined with code coverage, it can eliminate a ton of bugs before they get released, both subtle and glaring. As an oversimplified example, ever been to r/GamePhysics on Reddit? Ideally, those could have been caught with unit and behavior testing
This video is an advertisement for resharper. Unit Tests are not done like this at all. Unit Tests test source code. There is no source code here. Just code created for the unit test.
so tdd ?