Project Setup: Automated Testing with Make (using queue example)

  Рет қаралды 35,299

Jacob Sorber

Jacob Sorber

3 жыл бұрын

Patreon ➤ / jacobsorber
Courses ➤ jacobsorber.thinkific.com
Website ➤ www.jacobsorber.com
---
Project Setup: Automated Testing with Make (using queue example) // Continuing our recent series of videos about setting up programming projects, in this video I show you how to make automated testing easy by integrating it into your makefile, using the criterion testing framework. The example builds on the queue data structure from a previous video. Remember, if it isn't easy, you probably won't do it.
Related Videos:
Testing: • Produce better code fa...
Queue/ADT: • Make your Data Type mo...
Project Setup: • More Tips for Setting ...
Make videos: • Learn make in 60 seconds.
***
Welcome! I post videos that help you learn to program and become a more confident software developer. I cover beginner-to-advanced systems topics ranging from network programming, threads, processes, operating systems, embedded systems and others. My goal is to help you get under-the-hood and better understand how computers work and how you can use them to become stronger students and more capable professional developers.
About me: I'm a computer scientist, electrical engineer, researcher, and teacher. I specialize in embedded systems, mobile computing, sensor networks, and the Internet of Things. I teach systems and networking courses at Clemson University, where I also lead the PERSIST research lab.
More about me and what I do:
www.jacobsorber.com
people.cs.clemson.edu/~jsorber/
persist.cs.clemson.edu/
To Support the Channel:
+ like, subscribe, spread the word
+ contribute via Patreon --- [ / jacobsorber ]
Source code is also available to Patreon supporters. --- [jsorber-youtube-source.heroku...]

Пікірлер: 60
@TheCocoaDaddy
@TheCocoaDaddy 3 жыл бұрын
Bravo!!!! At my first programming job, we used make for a lot of our regression testing along with a ton of other stuff. We didn't use a framework, so we wrote unit test programs that tested all of our base classes. We wrote integration test programs to test our application and we used it extensively for environment setup (e.g. database "priming") and for test result comparison (e.g. report comparison, in some cases). I don't use make at all now, but sometimes I miss the "old days". Given the right targets, I could make a code change and run only the related tests OR I could run make "clean" and run the full regression suite. At one point, we had so many test cases, we had to split our build into two: one that ran the regression tests deemed most important to run and one that ran absolutely everything. I believe the second one had close to 300 tests (maybe a little more). Anyway, GREAT video and thanks for posting!
@JacobSorber
@JacobSorber 3 жыл бұрын
You're welcome.
@codebreakthrough
@codebreakthrough Жыл бұрын
This video has been tremendously helpful, thank you!
@fillempie1501
@fillempie1501 3 жыл бұрын
Good tip!. I found testing frameworks always clumsy to use. This one is rather easy. Have already used it and found some bugs in my functions. Implemented the tests it in my autotools setup.
@neillunavat
@neillunavat 3 жыл бұрын
I didnt even know you can do testing with make :o I owe all my C and C++ knowledge to you. Thank you so much.
@JacobSorber
@JacobSorber 3 жыл бұрын
Any time!
@neillunavat
@neillunavat 3 жыл бұрын
@Newtube link me resources. I am a bit naive being self taught.
@neillunavat
@neillunavat 3 жыл бұрын
@Newtube im just 15 bruv. But yeah, i know what i need to know and i only watch those that i find informative like Mr. Jacob. Just love his videos...
@KarlKatten
@KarlKatten 3 жыл бұрын
@Newtube Imagine complaining about the quality of someone's work when you literally just post stuff other people have made
@lucasteixeira5346
@lucasteixeira5346 3 жыл бұрын
Extremely useful video. Clear and meaningful info. Thanks a lot
@JacobSorber
@JacobSorber 3 жыл бұрын
You're welcome. Glad it was helpful.
@neerajkale
@neerajkale 3 жыл бұрын
Always.... Always learning something new and useful on your channel....
@JacobSorber
@JacobSorber 3 жыл бұрын
Wonderful. That's the goal.
@neerajkale
@neerajkale 3 жыл бұрын
@@JacobSorber FYI, in one of my previous companies, we used Robot Framework for Integration/Feature testing for an ECU for cranes. I never got a chance to look into how things have been setup, probably because I joined the project when 70% work was done, but all I remember is that we wrote few test keywords in a python file, write test cases in a txt file using those keywords and test the new Application feature that we wrote in C. It was pretty easy to use and would give a nice result output in an html file.
@timokkko
@timokkko 3 жыл бұрын
Could you make a follow up video about how to ensure that a test is not actual using periferal hardware but uses mocks or stubs?
@benjaminshinar9509
@benjaminshinar9509 3 жыл бұрын
really great!
@edgeeffect
@edgeeffect 10 ай бұрын
This is cool! I've often wondered how "you people' do automated testing in C.
@vvinoth514
@vvinoth514 3 жыл бұрын
❤️ From India
@JacobSorber
@JacobSorber 3 жыл бұрын
❤ from South Carolina. Thanks for being here.
@DanielMuringe
@DanielMuringe Жыл бұрын
You post some really legit content.
@sumdim6427
@sumdim6427 3 жыл бұрын
Nice!
@jessiehopper
@jessiehopper 2 жыл бұрын
I've been using the Catch2 framework to test my C code lately. It requires only that you add one header file and you're good to go.
@rohitjoshi4341
@rohitjoshi4341 2 жыл бұрын
I really like your videos on make. I would appreciate if you could provide videos where we can use makefile to link 3 party libraries like boost (header files libraries) and unlike boost lib. In both way shared or dynamic linking and static linking. Also, I would like if you can make videos on best practices while making a makefile. Also, my personal question can we use a nested makefile. I mean we add makefile of small projects then combine them to make a bigger one while making the project. If we can can you add how to do it. Also, best practices for it.
@dzious
@dzious 3 жыл бұрын
Hi, Just a little warning, I've got a ln issue few years ago with criterion. When I used a structure with more than 12 elements (if I remember correctly) it used to make tests fail. An other library that you can use to test your code which doesn't have this issue is Gtest (from Google) Overall this is a good video as always. Really good introduction to tests and how to implement them in a project. Maybe you should just add a link to Criterion in the description to make it easier for people to find the lib and the assertion references. I'll add few commands to my comment later on which can be useful with criterion
@JacobSorber
@JacobSorber 3 жыл бұрын
Interesting. Thanks. I haven't run into this issue, but I might just not put enough things in my structs. 🤔 I'll have to check it out.
@ivankryvosheia446
@ivankryvosheia446 2 жыл бұрын
Extremely useful! Question: is it a good method for cross-compilation? I mean, I develop for MCU but compile on my linux desktop. Or I have to somehow run tests on a target? thanks
@chonchjohnch
@chonchjohnch 2 жыл бұрын
My habit is to create my first make statement with all my settings and files and whatnot and then factor things out
@t0m0b0nes
@t0m0b0nes 3 жыл бұрын
Great video as always 🙏 Now there is no excuse anymore to not use unit testing in my current/following project 👍 One general question about unit testing: Would you only test the interfaces (.h files) or also functionality in the actual implementations (.c files) with unit testing? For me, my naive concept of unit testing is just testing the interfaces. Is that too narrow? Best wishes from Munich! ☀️
@JacobSorber
@JacobSorber 3 жыл бұрын
Hi Thomas! I would recommend testing everything you can. The smaller the "units" are that you are testing, the easier it is going to be to make sure you're testing everything. Testing the external-facing interfaces is usually easier than testing internal auxiliary functions. And, if testing those internals becomes too painful, that's ok. The point is to make sure that your tests exercise all of your code - all of your functions/lines of code as well as each of your interesting edge cases. So, the bigger the "unit" the more thought needs to go into testing it thoroughly. I hope that helps. Best of luck with the project.
@sleepib
@sleepib 2 жыл бұрын
Any ideas for automated testing of embedded code? The only thing I can think of that sounds like a reasonable use of time is to choose a platform like raspberry pi, where you can develop on the target hardware, or at least something close enough to run natively. Though I don't have any ideas for something like an 8051 microcontroller.
@jerrycrane6830
@jerrycrane6830 2 жыл бұрын
Great video,. I notice that Criterion doesn't support mocking. What mocking package do you use with it?
@daniellowry
@daniellowry 2 жыл бұрын
Word of warning with the $(RM) it can and will remove your OS and code if you're not careful. I lost a week of work and a bunch of OS configuration when i went to make and it ran the clean step. Be very careful to make sure you've got it right before running make as you won't know that it's destroying everything before its too late
@honey-py9pj
@honey-py9pj 3 жыл бұрын
I know it's called unit testing but in order to check my result for a school assignment which may include multiple functions (or any expect of main) , can I still use a unit testing framework and treat my whole program as a function? to test?
@LeFede
@LeFede 4 ай бұрын
how can I use it on windows?
@k8236
@k8236 3 жыл бұрын
Great video Jacob! How would I go about using criterion on another machine-VM gets the code from a git repo? Any help would be greatly appreciated!
@JacobSorber
@JacobSorber 3 жыл бұрын
Yes, you could do it that way. I often use vagrant to create the VM and then just share a folder between host and guest. But, a git repo would work, as well.
@k8236
@k8236 3 жыл бұрын
@@JacobSorber I ended up using a modified minunit setup! Just made it fancy with colours and more testing options! Thank you.
@mrafayshams3089
@mrafayshams3089 Жыл бұрын
How can I write my unit tests when using an IDE like MPLAB X? If I create a new folder named tests and in it, I write my unit tests; I don't want them to be compiled and be part of the actual code that will go into the microcontroller. I only want to run the unit tests when I need to or whenever I build the main code. Please guide as I'm very new to this.
@sumitbhosale3401
@sumitbhosale3401 3 жыл бұрын
Nice Explantion. But Can You Please Make On Video In Graph. Thanks
@muhammedthahirm423
@muhammedthahirm423 11 ай бұрын
is it fine if we haven't freed memory in test file. will it automatically be freed if any exception occurred?
@JacobSorber
@JacobSorber 11 ай бұрын
Any time a process ends, any non-shared memory will be unmapped.
@KangJangkrik
@KangJangkrik 2 жыл бұрын
Any idea how to use CMAKE instead? My team currently using CMAKE as a build tool but we use python instead to test because nobody knows how to do that in CMAKE
@pseudopseudo3679
@pseudopseudo3679 Жыл бұрын
Is it a poor idea to just use a set of standard assertions to test rather than criterion?
@diceandbricks
@diceandbricks 3 жыл бұрын
Nice. How does criterion detect and call each test case?
@dzious
@dzious 3 жыл бұрын
Criterion uses macros to "detect" each test case and build its function at compile time if you use VScode you han hover the Test keyword and you'll see the implementation of it
@michealking6425
@michealking6425 3 жыл бұрын
Where can I get the criterion library on windows?
@joegoosebass3958
@joegoosebass3958 Жыл бұрын
Yea and how did he install it! waste of time video
@wilfreddv
@wilfreddv 3 жыл бұрын
The "Test" functions (?) look weird to me, and especially the TestSuite one with the `.init=suitsetup`. Can someone tell me what is going on? Heavy preprocessor use?
@killermonkey1392
@killermonkey1392 3 жыл бұрын
Without having looked at it at all, I'll take a wild guess and say that most of it are infact preprocessor macros, and that the `.init=suitesetup` are probably copy-pasted into a Struct initialization.
@rmando_v
@rmando_v 3 жыл бұрын
Wow :0
@neerajkale
@neerajkale 3 жыл бұрын
Looking forward to CMake.
@rajamchakradar6711
@rajamchakradar6711 Жыл бұрын
hi Iam new to automated unit testing , i have followed you in this vedio and try to frame this framework,but dont know why i cant able to get output as it shows in your system .In my case makefile is not linked with test file and getting this in output screen ar -cvrs lib/hello.a obj/hello.o a - obj/hello.o for test in ; do ./$test; done can you please help me with this..
@DipankarDas-cm1zs
@DipankarDas-cm1zs 2 жыл бұрын
Which is the best testing framework?
@DipankarDas-cm1zs
@DipankarDas-cm1zs 2 жыл бұрын
for C
@joegoosebass3958
@joegoosebass3958 Жыл бұрын
The one you can get working
@abcddd580
@abcddd580 3 жыл бұрын
Dr.Sorber, do you use CMake? If so, I'd appreciate if you could do a series on it.
@joegoosebass3958
@joegoosebass3958 Жыл бұрын
don't waste your time, if you really must then there's a course on UIdemy.
@joegoosebass3958
@joegoosebass3958 Жыл бұрын
Whats the point of this video if you don't show us how to install the testing library?
@JacobSorber
@JacobSorber Жыл бұрын
By that logic, nearly all of my videos are pointless, because they don't show you how to buy and set up your computer.
@cernejr
@cernejr 3 жыл бұрын
Please do not use make for testing in 2021, just don't. Use python, or some other readable and maintainable language/platform. For building projects make is still fairly competitive (especially when used with cmake), but for testing it is a really poor choice.
The Good and Bad of Automatic Make Rules
11:24
Jacob Sorber
Рет қаралды 9 М.
You Can't Unit Test C, Right?
23:09
LinuxConfAu 2018 - Sydney, Australia
Рет қаралды 51 М.
لقد سرقت حلوى القطن بشكل خفي لأصنع مصاصة🤫😎
00:33
Cool Tool SHORTS Arabic
Рет қаралды 22 МЛН
Make your Data Type more Abstract with Opaque Types in C
13:41
Jacob Sorber
Рет қаралды 49 М.
Test-Driven Development // Fun TDD Introduction with JavaScript
12:55
Thoughts About Unit Testing | Prime Reacts
11:21
ThePrimeTime
Рет қаралды 216 М.
How To Structure A Programming Project…
19:00
Tech With Tim
Рет қаралды 91 М.
How to Write Function-Like Preprocessor Macros (C example)
13:59
Jacob Sorber
Рет қаралды 41 М.
Do you even test? (your code with CMake)
12:38
Code for yourself
Рет қаралды 20 М.
How to Check Your Pointers at Runtime
14:12
Jacob Sorber
Рет қаралды 31 М.
When do I use a union in C or C++, instead of a struct?
11:18
Jacob Sorber
Рет қаралды 68 М.
Can I Handle Exceptions with Try Catch in C? (setjmp, longjmp)
11:13
How Senior Programmers ACTUALLY Write Code
13:37
Thriving Technologist
Рет қаралды 1,5 МЛН