Minor correction, the --test-dir flag was only added in CMake 3.20, so if you have an older version, run the tests with these commands instead: cd build GTEST_COLOR=1 ctest --output-on-failure -j12
@@CodeForYourself I’ve actively searched for cmake + gtest setup tutorials and they help but they get really confusing really fast. I randomly got recommended this video and, no offence to the other guys but, this is 100x better.
This was a very infomative, engaging and entertaining video. Great work!!! Would love to see a video on your git workflow and if you use continuous integration with github. Thank you
Hi Igor, great content once again, thanks! One minor comment: looks like for using the "--test-dir build" option, at least CMake 3.20 is required. I am using 3.16 and took some time to figure out why it didn't discover any tests (well not too much as the message was pretty clear in saying that it was not looking for tests in the build folder, but still I expected an error or something like that!)
When I type #include the IDE doesn't find that file. In fact, even if I try to locate the file in the googletest folder and I type it in manually, the IDE still signals that the file cannot be found. What should I do? Where could the problem come from?
It is hard to answer your question precisely unfortunately as I don't know what you did before and which IDE you are using? Did you follow the video precisely? Did you copy all the code from the video script?
@@CodeForYourself Yep, I did everything in the video, even started over with a new project and followed every step. I was able to solve the problem by importing the framework automatically from GitHub and restarting the IDE. The folder structure was a lot less complicated. I also had a hard time understanding the dependencies in the CMakeLists file, but once I got that right and linked everything with the framework, it was fine. I had a few moments where I got confused during the video and maybe did something wrong and maybe that's why it didn't work. Anyway I'm glad it works now and that I was able to submit my programming assignment on time.
@@Andrei-cp5jr glad that it eventually worked out! What I’m a bit confused about is what do you mean by an IDE? Which one do you use? I find that heavy IDEs are very cumbersome to use and when you’re starting out I would suggest to only use text editors without the semantic autocomplete as this makes one learn faster in my experience.
Not too many. And mostly quite obscure. If we have a weird network configuration, like a firewall it feels more cumbersome to set up FetchContent, at least I remember struggling with it recently but I don't remember exactly what was so hard about it. 🤷♂️ Just remember it was something with permissions. The other thing that comes to mind is a situation when I need to clean and rebuild code without access to the internet. When using FetchContent the build folder including all external sources will be removed. This situation bit me a couple of times before. With the submodules as long as they were checked out when we had internet we're going to be good. There might be other reasons but as you see the ones I have are pretty obscure. FetchContent is not a bad solution, just a little bit finicky at times for my taste.
@@CodeForYourself ah.. I see the advantage of not deleting the external sources when rebuilding. on my commute to the office my laptop isn't connected to the internet mostly and it'll be nice to still have the external sources available
Python and java (and all languages that run on the jvm) have build systems that can access library repositories. It's just then a matter of declaring the exact version of the dependency we use in our code. The library is then fetched automatically by the build system (including testing frameworks). Isn't there an equivalent thing for c++?
Not built into the language. I guess just as it is not built into python for example. For python you would use pip, for C++ there is Conan or CPM (the ones that come to mind). They are not as standardized though.
What I don’t understand is was CTest actually gives you here. I build my GoogleTest based Unit Test projects with Cmake but without using CTest and I just run the created Unit Test executable. It gives me the exact same GTest output as in your video, so I don’t really get what CTest is for?
CTest is really just a way to "register" gtest with the rest of CMake. So that you could run the ctest binary from the same folder where you are building from. It makes sure you can run all the test targets in a unified way. Imagine having multiple test targets in multiple folders. As long as they all are registered through CTest you can run them all with a single unified command. Which is by the way the same should you use a different testing framework as an additional benefit. Does this make any sense?
@whac-a-robot8623 it should be just the build folder itself. So you have to change the directory into that build folder and run the cmake command from there. If that doesn’t work out I’ll have a look more deeply into this.
@@CodeForYourself I understood it now. For quick reference for others you putting my solution here. Command 1 : cd build . Command 2 : GTEST_COLOR=1 ctest --output-on-failure -j12. Thank you for the support.
I seriously thought you were the LangFocus channel guy, I was like: "wait, does this guy also code?" Write the LangFocus channel and you gonna see that you guys are mostly identical. OMG
@ interesting, I would say your face is mostly similar, but the other guy’s face is a bit more broad. I think you guys have mostly the same eyes, same nose and same mouth, except for the hair. I showed you both for some of my friends just to make sure that I’m not the only one and most of them agreed that you guys look similar to each other except for one or two, but they also agreed that you have similarities😁
Why is the method where we download GTest sources, save them to our system, build them, and then include them in our project using something like this (look down) now deprecated? enable_testing() find_package(GTest REQUIRED) include(GoogleTest) add_executable(tests tests.cpp ) target_link_libraries(tests GTest::gmock GTest::gtest ) gtest_discover_tests(tests)
@@ozimandias1858 well, deprecated is a strong word for it, you’re right. But it is discouraged. The suggested way is to “live at head” as mentioned in their readme: github.com/google/googletest#live-at-head
@@arkadiuszszulc3303 I think I largely agree with you nowadays and that’s why in the recent videos I’ve done away with clocks altogether. That being said, it is a thing of personal preference and I do know people who prefer it with clicks because they like it aesthetically. It is hard to tailor to everybody. 😅 At this point I just hope it is not too distracting.
Minor correction, the --test-dir flag was only added in CMake 3.20, so if you have an older version, run the tests with these commands instead:
cd build
GTEST_COLOR=1 ctest --output-on-failure -j12
This is amazing, thanks.
I'm interested in your computer chair. Is it good for tall people?
@@HylianEvil well, it’s ok. It is a simple IKEA chair 🤷♂️
That clip of cat failing to jump is exact visual representation of me running my code! 🤣🤣
Yeah, don't even mention it! Been there many times myself 🫂
This tutorial is criminally underrated. You deserve more subscribers. 👍
@@CodeForYourself I’ve actively searched for cmake + gtest setup tutorials and they help but they get really confusing really fast. I randomly got recommended this video and, no offence to the other guys but, this is 100x better.
Wow, this really warms my heart. Thanks for such a praise! This is _really_ important to me. 🙏
Looking forward to git submodule video. Thank you for another awesome video.
This was a very infomative, engaging and entertaining video. Great work!!! Would love to see a video on your git workflow and if you use continuous integration with github. Thank you
Gotcha. Will record this video in the coming weeks most probably. Thanks!
That pretty much helpful and so easy to understand, thank you!
Awesome, You are rock man!!!... 🌹💖
Hi Igor, great content once again, thanks!
One minor comment: looks like for using the "--test-dir build" option, at least CMake 3.20 is required. I am using 3.16 and took some time to figure out why it didn't discover any tests (well not too much as the message was pretty clear in saying that it was not looking for tests in the build folder, but still I expected an error or something like that!)
Yeah, that is correct. With the older cmake we have to run the tests from the tests folder 🤷♂️ Sorry for not mentioning it upfront.
Thanks a lot for your tutorial! It's very clear.
Thanks for watching and for the kind words!
Контенту від українців стає більше і це не може не радувати!) Дякую)
When I type #include the IDE doesn't find that file. In fact, even if I try to locate the file in the googletest folder and I type it in manually, the IDE still signals that the file cannot be found. What should I do? Where could the problem come from?
It is hard to answer your question precisely unfortunately as I don't know what you did before and which IDE you are using? Did you follow the video precisely? Did you copy all the code from the video script?
@@CodeForYourself Yep, I did everything in the video, even started over with a new project and followed every step. I was able to solve the problem by importing the framework automatically from GitHub and restarting the IDE. The folder structure was a lot less complicated. I also had a hard time understanding the dependencies in the CMakeLists file, but once I got that right and linked everything with the framework, it was fine. I had a few moments where I got confused during the video and maybe did something wrong and maybe that's why it didn't work. Anyway I'm glad it works now and that I was able to submit my programming assignment on time.
@@Andrei-cp5jr glad that it eventually worked out! What I’m a bit confused about is what do you mean by an IDE? Which one do you use? I find that heavy IDEs are very cumbersome to use and when you’re starting out I would suggest to only use text editors without the semantic autocomplete as this makes one learn faster in my experience.
@@CodeForYourself I'm using CLion
Does this code at the end of each test run attempt to update submodules? Will this slow down the testing process if tests are run frequently?
Thanks for the question! The update code is only run at the cmake configuration stage. So it is not run when the tests are run. Does this make sense?
First😎
Another fascinating video, Igor🔥
Keep it up✨
Can i ask what are the advantages of adding google test as submodule over using FetchContent?
Not too many. And mostly quite obscure. If we have a weird network configuration, like a firewall it feels more cumbersome to set up FetchContent, at least I remember struggling with it recently but I don't remember exactly what was so hard about it. 🤷♂️ Just remember it was something with permissions.
The other thing that comes to mind is a situation when I need to clean and rebuild code without access to the internet. When using FetchContent the build folder including all external sources will be removed. This situation bit me a couple of times before. With the submodules as long as they were checked out when we had internet we're going to be good.
There might be other reasons but as you see the ones I have are pretty obscure. FetchContent is not a bad solution, just a little bit finicky at times for my taste.
@@CodeForYourself ah.. I see the advantage of not deleting the external sources when rebuilding. on my commute to the office my laptop isn't connected to the internet mostly and it'll be nice to still have the external sources available
Python and java (and all languages that run on the jvm) have build systems that can access library repositories. It's just then a matter of declaring the exact version of the dependency we use in our code. The library is then fetched automatically by the build system (including testing frameworks). Isn't there an equivalent thing for c++?
Not built into the language. I guess just as it is not built into python for example. For python you would use pip, for C++ there is Conan or CPM (the ones that come to mind). They are not as standardized though.
What I don’t understand is was CTest actually gives you here. I build my GoogleTest based Unit Test projects with Cmake but without using CTest and I just run the created Unit Test executable. It gives me the exact same GTest output as in your video, so I don’t really get what CTest is for?
CTest is really just a way to "register" gtest with the rest of CMake. So that you could run the ctest binary from the same folder where you are building from. It makes sure you can run all the test targets in a unified way. Imagine having multiple test targets in multiple folders. As long as they all are registered through CTest you can run them all with a single unified command. Which is by the way the same should you use a different testing framework as an additional benefit. Does this make any sense?
Hi Igor, I am using CMAKE 3.16, when I tried the above I am getting a message stating that no tests found. How to resolve this?
Yeah, that’s a bit of a limitation. There was another comment under this video where we come up with a solution. Does that solution work for you?
@@CodeForYourself where is that test folder is mapped? I couldn't find it.
@whac-a-robot8623 it should be just the build folder itself. So you have to change the directory into that build folder and run the cmake command from there. If that doesn’t work out I’ll have a look more deeply into this.
@@CodeForYourself ok will check and let you know
@@CodeForYourself I understood it now. For quick reference for others you putting my solution here. Command 1 : cd build . Command 2 : GTEST_COLOR=1 ctest --output-on-failure -j12.
Thank you for the support.
This video is so cool. Is it possible to use google test in the microcontroller project??
I guess so, depends on your setup. Which microcontroller are you talking about?
Great video!
I seriously thought you were the LangFocus channel guy, I was like: "wait, does this guy also code?"
Write the LangFocus channel and you gonna see that you guys are mostly identical. OMG
@@mohammedkamil5320 ok, to me we seem to be quite different but I like these types of connections. What would you say is similar? 😅
@ interesting, I would say your face is mostly similar, but the other guy’s face is a bit more broad. I think you guys have mostly the same eyes, same nose and same mouth, except for the hair. I showed you both for some of my friends just to make sure that I’m not the only one and most of them agreed that you guys look similar to each other except for one or two, but they also agreed that you have similarities😁
@ I don’t mind at all. Maybe one day I’ll have as many subscribers too 😅
Hey, Which editor did you use here?
@@hurainjinnath I’m using VS Code exclusively in this course.
@@hurainjinnath oh and there is also the standard macOS terminal
@@CodeForYourself thanks ☺
Sure, my pleasure!
Why is the method where we download GTest sources, save them to our system, build them, and then include them in our project using something like this (look down) now deprecated?
enable_testing()
find_package(GTest REQUIRED)
include(GoogleTest)
add_executable(tests
tests.cpp
)
target_link_libraries(tests
GTest::gmock
GTest::gtest
)
gtest_discover_tests(tests)
@@ozimandias1858 well, deprecated is a strong word for it, you’re right. But it is discouraged. The suggested way is to “live at head” as mentioned in their readme: github.com/google/googletest#live-at-head
@@ozimandias1858 they also only provide the fetch_content example in their docs: google.github.io/googletest/quickstart-cmake.html
Okay, thank you!
FOR THE ALGORHYTHM!!!
😂
Useful info but why these noisy keyboard clicks, ha? It is a common knowledge that signs in an editor come from a keyboard. It just distracts.
@@arkadiuszszulc3303 I think I largely agree with you nowadays and that’s why in the recent videos I’ve done away with clocks altogether. That being said, it is a thing of personal preference and I do know people who prefer it with clicks because they like it aesthetically. It is hard to tailor to everybody. 😅 At this point I just hope it is not too distracting.