just ME
just ME

Reputation: 1827

how to test c code or libraries written in c

I am new to testing field. I would like to firstly ask in what ways can a C application be tested (a C framework or a C tool), how should I start, what are the steps also which are the best tools I can use for testing C code.

Need some help and some documentation. Thx

Upvotes: 0

Views: 467

Answers (1)

fkl
fkl

Reputation: 5535

What a unit testing tool or frame work usually does is automate all input sets and check outputs for valid results as well as do negative tests i.e. put invalid values and see appropriate response, such as the system should at least remain stable. For e.g. if a function says it only processes positive numbers, ideally it should be able to say "invalid data" when passed a negative number, instead of giving wrong answers or worst getting crashed)

On an api level say if you have a function which takes a number and returns it's square, you write a script (or have a tool) which calls that function repeatedly passing it all valid inputs (or at least all inputs of different types such that each class is covered). This would mean testing boundary conditions (min max values), basic use case conditions and negative conditions etc.

Beyond unit tests you can do white box testing. Such as code coverage i.e. ensuring you have executed test cases which cover most if not all code paths.

Automating some/most of above so that they can be repeatedly executed and validated every time a change is made is called regression testing.

Then there are several other areas of testing such as localization, globalization, security testing etc. to name a few.

Upvotes: 1

Related Questions