Home > Enterprise >  How to get started with C unit tests
How to get started with C unit tests

Time:06-12

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?

CodePudding user response:

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();}
  • Related