Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to get started with C++ unit tests

I am just starting with c++ unit testing. I want to create simple tests (without using any framework) using assert commands. How can I start with that?

Should I make different functions for tests and call them in the main in a single file or should I make separate file for each test?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Just use it like assert(<output-to-test>==<expected-value>)

#include <cassert>
int square(int x){return x*x}
void test1(){
   assert(square(1)==1)
   assert(square(2)==4)
}
void main(){test1();}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading