Google c++ Test Mocking Framework Part - 4: Writing Mocks using c++ gtest and c++ gmock

  Рет қаралды 88,172

Cognitive Programmer

Cognitive Programmer

Күн бұрын

Пікірлер: 73
@renanrosa5527
@renanrosa5527 6 жыл бұрын
Currently the best tutorial about gmock in youtube.
@Cognitive-Programmer
@Cognitive-Programmer 6 жыл бұрын
Thanks for your comment...
@BarathanG2502
@BarathanG2502 3 жыл бұрын
Watching this video in 2021 and it's still one of the best gmock tutorials
@Cognitive-Programmer
@Cognitive-Programmer 3 жыл бұрын
Thank you so much 🙏🙏🙏
@sbsyr5555
@sbsyr5555 2 жыл бұрын
@@Cognitive-Programmer nl. Nlmb. N bbig pp. Cc o
@valentinabonetti1808
@valentinabonetti1808 3 жыл бұрын
Best tutorial on Google Mock I've found so far! Clear and to the point. Thanks!
@Cognitive-Programmer
@Cognitive-Programmer 3 жыл бұрын
Thanks a lot for your comment 🙏🙏🙏
@bilaln6896
@bilaln6896 4 ай бұрын
Great intro to gmock.
@Cognitive-Programmer
@Cognitive-Programmer 4 ай бұрын
Thanks for your kind comment 🙏
@truthadjustr
@truthadjustr 6 жыл бұрын
Nice tutorial. At 18'30", your line 46 has type mismatch Init returns int but login2 returns bool. I was at first confused, but then it clicked on me when i realized that GMock can control the behaviour of a mocked function. GMock can make it return 69, for example. And then, the assert portion must do the necessary check.
@Cognitive-Programmer
@Cognitive-Programmer 3 жыл бұрын
👉 Follow my Learnings and Journey beyond software development 🎦 @ bit.ly/insightfuldaksh
@游柏皓-q3w
@游柏皓-q3w 7 ай бұрын
Thank you! This tutorial is very useful for me as a beginer.
@Cognitive-Programmer
@Cognitive-Programmer 7 ай бұрын
Thanks for your comment 🙏
@Jam18123
@Jam18123 6 ай бұрын
thank you for a very nice tutorial. real case challenges - interface functions will not be virtual always, my component may not always have references.
@spicytuna08
@spicytuna08 6 жыл бұрын
i am a coder. i really didn't understand the complexities of testing. thanks again.
@Cognitive-Programmer
@Cognitive-Programmer 6 жыл бұрын
Thanks for your comment
@huyvole9724
@huyvole9724 4 жыл бұрын
If you using Sleep function, you will see how Mock setup (Mock don't do anything with any parameter, it will return your value), simple show for beginer
@baqtronic7704
@baqtronic7704 5 жыл бұрын
I really liked all the parts of this series, it is everything very concise and well explained. Thanks a lot! I had some difficulties with the pronunciation, so maybe it could be helpful for others as well to add subtitles... Thanks again!
@Cognitive-Programmer
@Cognitive-Programmer 5 жыл бұрын
Thanks for your valuable comment.. I am working on a new series on the same topic and shall take care of things
@mahimohanettumanoor1396
@mahimohanettumanoor1396 3 жыл бұрын
Good video on Gmock .
@Cognitive-Programmer
@Cognitive-Programmer 3 жыл бұрын
Thanks for your comment 🙏🙏🙏
@memphisraines6858
@memphisraines6858 5 жыл бұрын
Thank you for this tutorial! Absolutely fantastic!
@Cognitive-Programmer
@Cognitive-Programmer 5 жыл бұрын
Thanks for your comment
@PranaySoniKumar
@PranaySoniKumar 4 жыл бұрын
Thanks you!! It brief, to the point and very useful to get started!
@Cognitive-Programmer
@Cognitive-Programmer 4 жыл бұрын
Thanks for your comment 🙏🙏🙏
@DiegodeSousa
@DiegodeSousa 6 жыл бұрын
Hello that's me again xD Another little feedback is that in last example that we are exploring the usage of ON_CALL macro to execute randomly login() and login2() member function using the rand() function we need to initialize random seed calling srand () function, otherwise member function login2() will be called in any circumstance. Thus, code should look like this: int Init(string username, string password) { srand (time(NULL)); int rvalue = rand() % 2; ... source: www.cplusplus.com/reference/cstdlib/rand/ I hope that it helps somebody.
@Cognitive-Programmer
@Cognitive-Programmer 6 жыл бұрын
Thanks again.. :)
@wizardy6267
@wizardy6267 6 жыл бұрын
Great video! only thing confused me was when you named a variable as 'rvalue' my first reaction was no~ it is not a rvalue and then my thoughts went to a totally different path about a whole different set of "?value" things...pretty much missed following 1 minute of your speech. Anyway, thank you for your help, this is a really good tutorial :D
@Cognitive-Programmer
@Cognitive-Programmer 6 жыл бұрын
Thanks for your comment
@kevinduigou3212
@kevinduigou3212 6 жыл бұрын
Very interesting video! Thank you from France!
@Cognitive-Programmer
@Cognitive-Programmer 6 жыл бұрын
Thank you very much for your comment
@studywithdas4245
@studywithdas4245 4 жыл бұрын
very good tutorial
@Cognitive-Programmer
@Cognitive-Programmer 4 жыл бұрын
Thanks for your comment 🙏🙏🙏
@dantheman8862
@dantheman8862 5 жыл бұрын
Super helpful video. Thanks for this!
@Cognitive-Programmer
@Cognitive-Programmer 5 жыл бұрын
Thanks for your comment
@huyvole9724
@huyvole9724 4 жыл бұрын
Best ever! +1 like from Việt Nam
@Cognitive-Programmer
@Cognitive-Programmer 4 жыл бұрын
Thanks for your comment
@eigenfield
@eigenfield 2 жыл бұрын
Thank you so much for this tutorial. Is Times(1).WillOnce(Return(true)) doing a redundant check? Since WillOnce already implies once, therefore we can remove the Times(1) constraint. Thanks for any insight on this regard.
@matthewp4046
@matthewp4046 3 жыл бұрын
Great video, thank you.
@Cognitive-Programmer
@Cognitive-Programmer 3 жыл бұрын
Thanks for watching my video and thanks for your comment 🙏🙏🙏
@srijanshashwat1965
@srijanshashwat1965 5 жыл бұрын
Does 0,1 or 2 specify the no. Of arguments?
@silviudema9315
@silviudema9315 6 жыл бұрын
Great tutorials !
@Cognitive-Programmer
@Cognitive-Programmer 6 жыл бұрын
Thanks for your comment
@beemavishnu
@beemavishnu 2 жыл бұрын
Thank you for your detailed explanation. I have a query. Do we need to keep 'virtual' always in DataBaseConnect. I tried without keeping and getting error as "Actual function call count doesn't match EXPECT_CALL".
@Cognitive-Programmer
@Cognitive-Programmer 2 жыл бұрын
Yes when I created this video.. check in stackoverflow if there are any latest developments in this Thank you 🙏
@BowDrawn115
@BowDrawn115 2 жыл бұрын
Very nice tutorial, how would you recommend to write a test that fetches some data from a database and also writes into it?
@eigenfield
@eigenfield 2 жыл бұрын
You have to perfectly simulate such situations and never to use external subsystem that can possibly fail.
@batluongnhan04_12
@batluongnhan04_12 2 жыл бұрын
dear all, i have a question, please see it help me! if in class MyDatabase, i have a function like : DataBaseConnect& returnOBject(){return dbC;} and, in the TEST function, i use db.returnOBject() instead of mdb inside EXPECT_CALL(db.returnOBject(), login()...).. it doesn't work, why? I know mbd is a referrence to dbC, but I just want to ask why it doesn't work. Thanks so much !
@sheminaboobacker8411
@sheminaboobacker8411 6 жыл бұрын
Can You explain how constructor of Mydatabase is created with reference of abstract class /interface
@Cognitive-Programmer
@Cognitive-Programmer 6 жыл бұрын
Hello You can initialize references in constructor using constructor initialization list and that's the reason for this code MyDatabase(DataBaseConnect & _dbc): dbc(_dbc) {} Hope it helps Thanks
@Arti53hk
@Arti53hk 2 жыл бұрын
Hello, if I inject a pointer of the calling class (injected class) instead of the reference, how can write the mock and the gtest for this special case ? ... Class MyDatabase{ DatabaseConnext* abc; Public: MyDatabase(DatabaseConnext* abc) : abc(abc) {} ; } ; Test (...,...) { MockDB* abc; MyDatabase db(abc) ; EXPECT_CALL(*abc, login(_, _)) // is this line correct? 😅 .Time(1) .willOnce(..); ... } When I make it, I get "segmentation fault" in the RegisterOwner() methode from class UntypedFunctionMockerBase
@rishabhagarwal3404
@rishabhagarwal3404 6 жыл бұрын
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
@bestganesh
@bestganesh 3 жыл бұрын
can we mock the function that calls std::thread function. e.g. void myfun() { std::thread(&threadfunction, this); } I want to test this function but I am getting error with terminate called without an active exception. That means thread is created and became out of scope and testing is terminated. :( Can you please tell me if it is possible to use std::thread in gmock?
@rajeevdey_8894
@rajeevdey_8894 Жыл бұрын
I think the test name should be InitTest. isn't itt?
@LastOfThem-d8b
@LastOfThem-d8b 3 жыл бұрын
For me biggest setback you can not mock non virtual function
@aryamangupta3919
@aryamangupta3919 3 жыл бұрын
How to mock static class used by another static static class?
@theboringtechguy
@theboringtechguy 3 жыл бұрын
I am getting error while including gmock.h, it says no such file or directory. Please let me know what I am missing
@Cognitive-Programmer
@Cognitive-Programmer 3 жыл бұрын
Hello.. you have to install gmock separately… please see gmock GitHub page for installation instructions..Thanks
@neohhueyli
@neohhueyli 4 жыл бұрын
Hi Sir, how to mock non virtual function?
@Sanatani-Bharat-108
@Sanatani-Bharat-108 4 жыл бұрын
How to unit test class with static methods?
@alyamajavier4963
@alyamajavier4963 5 жыл бұрын
Hello Sir please give time to answer to my question. I am new to googletesting. I can't compile, it keeps displaying Usr/bin/id: cannot find -lgmock collect2:error: ld returned 1 exit status
@ranjithks7
@ranjithks7 4 жыл бұрын
Same error to me as well although I have added -lgmock
@ranjithks7
@ranjithks7 4 жыл бұрын
Download googletest source and compile yourself. It worked for me
@PrashantAdlinge
@PrashantAdlinge 4 жыл бұрын
which editor you are using for code ?
@Cognitive-Programmer
@Cognitive-Programmer 4 жыл бұрын
Hello I am using Atom on Ubuntu
@freddymartinez8741
@freddymartinez8741 5 жыл бұрын
I got an error using Return inside WillOnce: "Use of undeclared identifier 'Return'" :(
@freddymartinez8741
@freddymartinez8741 5 жыл бұрын
i found the issue... i missed using namespace testing :D
@Cognitive-Programmer
@Cognitive-Programmer 5 жыл бұрын
Thanks
@kid-vf4lu
@kid-vf4lu 6 жыл бұрын
How often do you write mock-ups in practice?
@Cognitive-Programmer
@Cognitive-Programmer 6 жыл бұрын
Well it's bit subjective and depends upon the kind of the code. A not so perfect rule could be to use Mocks whenever you're using an API/interface which requires additional dependencies to run
@sameddonater
@sameddonater 3 жыл бұрын
Thank you brother
@Cognitive-Programmer
@Cognitive-Programmer 3 жыл бұрын
Thanks for your comment 🙏🙏🙏
Unit Tests and Test Doubles like Mocks, Stubs & Fakes
17:32
Cognitive Programmer
Рет қаралды 137 М.
I thought one thing and the truth is something else 😂
00:34
عائلة ابو رعد Abo Raad family
Рет қаралды 12 МЛН
快乐总是短暂的!😂 #搞笑夫妻 #爱美食爱生活 #搞笑达人
00:14
朱大帅and依美姐
Рет қаралды 14 МЛН
When Cucumbers Meet PVC Pipe The Results Are Wild! 🤭
00:44
Crafty Buddy
Рет қаралды 61 МЛН
The IMPOSSIBLE Puzzle..
00:55
Stokes Twins
Рет қаралды 192 МЛН
C# Unit Testing Best Practices for Great Code Coverage
17:52
Milan Jovanović
Рет қаралды 28 М.
Demo: Rapid prototyping with Gemma and Llama.cpp
11:37
Google for Developers
Рет қаралды 68 М.
how Google writes gorgeous C++
7:40
Low Level
Рет қаралды 956 М.
C++ testing with mocks is EASY and awesome!
10:00
Smok Code
Рет қаралды 19 М.
Professional Python Testing with Mocks
21:19
NeuralNine
Рет қаралды 61 М.
Unit Testing in C# 2022: 4. Mocking EXPLAINED SIMPLY [FakeItEasy]
20:01
the TRUTH about C++ (is it worth your time?)
3:17
Low Level
Рет қаралды 771 М.
I thought one thing and the truth is something else 😂
00:34
عائلة ابو رعد Abo Raad family
Рет қаралды 12 МЛН