Тёмный

Do you even test? (your code with CMake) 

Code for yourself
Подписаться 3,4 тыс.
Просмотров 18 тыс.
50% 1

It's time we talked about testing our C++ code! We chat about what testing is and look into how to integrate one of the most used testing frameworks (Googletest) into our CMake project.
Script 🎓
github.com/cpp-for-yourself/s...
Related materials 📄
- Googletest Primer: google.github.io/googletest/p...
- Video about CMake: • CMake - the essential ...
- Video about Libraries: • C++ libraries and what...
- CMake tutorial from which I took the submodule idea: cliutils.gitlab.io/modern-cmake/
Support Ukraine 🇺🇦
Ukraine is fighting a war against unprovoked russian aggression. Please donate to one of the funds to support them: www.defendukraine.org/donate
Please support my free work 🙏
- Through Patreon: / code_for_yourself
- Through GitHub Sponsors: github.com/sponsors/niosus
Contents
00:00 - Intro
00:53 - What is testing?
01:39 - Which framework to use?
02:18 - One way to integrate testing into your project
05:11 - Maybe, let's add the C++ code?
08:42 - A better way to integrate testing into your project
11:02 - Adding some magic
Reference
- Image of Wednesday taken from: deadline.com/gallery/wednesda...
- All the stock footage is from Pexels
- The cat video is from RU-vid

Опубликовано:

 

16 июн 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 66   
@CodeForYourself
@CodeForYourself Год назад
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
@kompila
@kompila Год назад
This is amazing, thanks.
@HylianEvil
@HylianEvil 6 месяцев назад
I'm interested in your computer chair. Is it good for tall people?
@CodeForYourself
@CodeForYourself 6 месяцев назад
@@HylianEvil well, it’s ok. It is a simple IKEA chair 🤷‍♂️
@siddevsam
@siddevsam 3 месяца назад
That clip of cat failing to jump is exact visual representation of me running my code! 🤣🤣
@CodeForYourself
@CodeForYourself 3 месяца назад
Yeah, don't even mention it! Been there many times myself 🫂
@longvuong2600
@longvuong2600 Год назад
Looking forward to git submodule video. Thank you for another awesome video.
@kuijaye
@kuijaye Год назад
Fantastic video! I had a lot of problem linking to gtest because I installed it on system... I fixed it with setting right environment variables, but this way is much better! About submodule, yes! Please show us how you would use git in projects
@tienvuhong3536
@tienvuhong3536 Месяц назад
That pretty much helpful and so easy to understand, thank you!
@blablabla7796
@blablabla7796 Год назад
This tutorial is criminally underrated. You deserve more subscribers. 👍
@blablabla7796
@blablabla7796 Год назад
@@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.
@CodeForYourself
@CodeForYourself Год назад
Wow, this really warms my heart. Thanks for such a praise! This is _really_ important to me. 🙏
@theintjengineer
@theintjengineer Год назад
First😎 Another fascinating video, Igor🔥 Keep it up✨
@MrCynosure4sure
@MrCynosure4sure Год назад
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
@CodeForYourself
@CodeForYourself Год назад
Gotcha. Will record this video in the coming weeks most probably. Thanks!
@andreacassotti2561
@andreacassotti2561 2 месяца назад
Thanks a lot for your tutorial! It's very clear.
@CodeForYourself
@CodeForYourself 2 месяца назад
Thanks for watching and for the kind words!
@reubenthomas1033
@reubenthomas1033 Год назад
Great video!
@ilarioantonioazzollini66
@ilarioantonioazzollini66 Год назад
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!)
@CodeForYourself
@CodeForYourself Год назад
Yeah, that is correct. With the older cmake we have to run the tests from the tests folder 🤷‍♂️ Sorry for not mentioning it upfront.
@onemoremagistr
@onemoremagistr 8 месяцев назад
Контенту від українців стає більше і це не може не радувати!) Дякую)
@silentage6310
@silentage6310 Месяц назад
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?
@CodeForYourself
@CodeForYourself Месяц назад
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?
@jcbrites
@jcbrites 6 месяцев назад
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++?
@CodeForYourself
@CodeForYourself 6 месяцев назад
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.
@jackie7023
@jackie7023 8 месяцев назад
This video is so cool. Is it possible to use google test in the microcontroller project??
@CodeForYourself
@CodeForYourself 7 месяцев назад
I guess so, depends on your setup. Which microcontroller are you talking about?
@keepgoing335
@keepgoing335 Год назад
Can i ask what are the advantages of adding google test as submodule over using FetchContent?
@CodeForYourself
@CodeForYourself Год назад
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.
@keepgoing335
@keepgoing335 Год назад
@@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
@BenUK1
@BenUK1 Год назад
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?
@CodeForYourself
@CodeForYourself Год назад
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?
@mek101whatif7
@mek101whatif7 Год назад
FOR THE ALGORHYTHM!!!
@CodeForYourself
@CodeForYourself Год назад
😂
@Andrei-cp5jr
@Andrei-cp5jr 6 месяцев назад
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?
@CodeForYourself
@CodeForYourself 6 месяцев назад
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?
@Andrei-cp5jr
@Andrei-cp5jr 6 месяцев назад
@@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.
@CodeForYourself
@CodeForYourself 6 месяцев назад
@@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.
@Andrei-cp5jr
@Andrei-cp5jr 6 месяцев назад
@@CodeForYourself I'm using CLion
@whac-a-robot
@whac-a-robot 2 месяца назад
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?
@CodeForYourself
@CodeForYourself Месяц назад
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?
@whac-a-robot
@whac-a-robot Месяц назад
@@CodeForYourself where is that test folder is mapped? I couldn't find it.
@CodeForYourself
@CodeForYourself Месяц назад
@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.
@whac-a-robot
@whac-a-robot Месяц назад
@@CodeForYourself ok will check and let you know
@whac-a-robot
@whac-a-robot Месяц назад
@@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.
Далее
Can you write a proper CMake library? | homework 📚
0:59
CMake - the essential package
27:54
Просмотров 8 тыс.
Нюша на премии МУЗ-ТВ 2024 #нюша
00:11
Introduction to Google Test and CMake
31:32
Просмотров 133 тыс.
Thoughts About Unit Testing | Prime Reacts
11:21
Просмотров 206 тыс.
why do header files even exist?
10:53
Просмотров 361 тыс.
Modern CMake for C++
11:38
Просмотров 38 тыс.
Introduction to CMake Crash Course
14:08
Просмотров 7 тыс.
You Can't Unit Test C, Right?
23:09
Просмотров 50 тыс.