3

I need to write a simple unit test that executes on a given .c file. I can't seem to find simple explanations or examples on the web to help me accomplish this. I've seen examples where unit testing frameworks such as cUnit are used.. but is this a necessity? Also, I need the unit test to be executable without using any IDE.

eerorika
  • 232,697
  • 12
  • 197
  • 326
jhj
  • 41
  • 1
  • 7
  • have a look at this: http://stackoverflow.com/questions/65820/unit-testing-c-code?rq=1 it contains good advice – Markon Jun 29 '16 at 10:01
  • 1
    thanks, but is using a testing framework essential? – jhj Jun 29 '16 at 10:04
  • 2
    Just use functions and asserts. – 2501 Jun 29 '16 at 10:07
  • Do you know of a simple example using functions and asserts? – jhj Jun 29 '16 at 10:10
  • Yes, but how would I perform asserts on an input file? i.e. checking if the output in `file x` is equal to some number? – jhj Jun 29 '16 at 10:20
  • Thanks for that example. How would I specify which parts of the input file the assert should check? I don't want to hard code the program to look at line x for example as the input file may vary in contents.. – jhj Jun 29 '16 at 10:27
  • So basically assume that the assert should perform on line 7 of a file? What would be the solution to avoid hard coding this? My aim is to receive files from students where I can then perform unit tests on to check if the correct output(s) are given.. – jhj Jun 29 '16 at 10:37
  • @jhj For this purpose I'd just compare results from a working program to your students output – Ishay Peled Jun 29 '16 at 12:10

0 Answers0