How do you do unit tests for C/C++ projects? What tools and frameworks are used?

  c++, question

How do you do unit tests for the C language project? What tools and frameworks are used?

In addition, may I ask if there are any convenient unit testing techniques for using Clion IDE?

RecommendCatch, please look directly at here first:
Introduction to C++ Unit Testing _Catch

Then your second question, how can Clion easily use unit tests? Use Catch directly, why? Because the author of Catch is now working in Clion, it is painless to embed Clion and provides more functions:To Catch a clion
The initial function is not listed, how to use it in the terminalCatchHow to use it in Clion, the generated result is in the console:

All tests passed (1 assertion in 1 test case)

Since integrated intoClionInside, it is natural to add some functions that IDE should have:

  • Added a separateUnit test tool, you can view the unit tests that the jump succeeded or failed.
  • Support unit test report export view, use case execution time.

Setting method:
Run | Edit Configurations -> “+” -> Catch Test
clipboard.png

Effect:
clipboard.png

If you want to know more, read the official documents written by the author directly:
https://blog.jetbrains.com/cl …

Update a c++ Unit Test Resource Link: Includes c++ Unit Test Framework /TDD Books/Online Courses
https://helpercode.com/2017/0 …

If only the algorithm library/standard library is written, thencatchThe most basic functions can meet the requirements. If the code has system calls/databases, mock is required, and priority is given to checkingcatchWhether the requirements are met; if not, usegmock.