0

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

just ME
  • 1,817
  • 6
  • 32
  • 53
  • 2
    [valgrind](http://valgrind.org/) is a great tool to check for memory usage errors among other things. – Eregrith Sep 05 '12 at 08:51
  • 1
    Are you searching for a unit testing framework? – Philipp Sep 05 '12 at 08:55
  • 1
    And [gdb](http://www.gnu.org/software/gdb/) is a great tool to debug. – Julien Fouilhé Sep 05 '12 at 09:05
  • possible duplicate of [testing code in C C++](http://stackoverflow.com/questions/1439172/testing-code-in-c-c) – Bo Persson Sep 05 '12 at 09:06
  • @Eregrith: "Testing" usually means unit testing, or functionality tests or similar. What Valgrind does is something between "testing" and "debugging"... – DevSolar Sep 05 '12 at 09:06
  • 1
    we used to write small main functions to check functionality of a particular module. There are some unit testing framework available but for small projects, they are bit overkill. – Aftnix Sep 05 '12 at 09:15
  • If you need unit test framework for C take a look at this [So thread](http://stackoverflow.com/questions/65820/unit-testing-c-code). – Agnius Vasiliauskas Sep 05 '12 at 10:15
  • @Aftnix: +1. A `main()` wrapped in `#ifdef TEST` turns source for a library function into a test executable testing that same function. – DevSolar Sep 05 '12 at 12:08

1 Answers1

1

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.

fkl
  • 5,412
  • 4
  • 28
  • 68
  • thx. could you give me some examples of tools or frameworks which i can use at unit testing, white box testing..so on? – just ME Sep 05 '12 at 11:20
  • One tool does not fit a specific type of testing. Rather it depends on your application. For e.g. WinRunner is one tool which can be used to automate UI testing. However, it simply have no or little use if your domain is NON UI for e.g. embedded or command line applications. Other examples that i have used are Breaking Point, Spirent etc. which again are highly specialized hardware for testing carrier grade networking equipment i.e. these devices can be configured to throw any type of network traffic against a device at a very high speed and report the responses. This is specific to networks. – fkl Sep 05 '12 at 18:28
  • For unit testing CUNIT is one good frame work for c. Though there are many http://en.wikipedia.org/wiki/List_of_unit_testing_frameworks Following might be a helpful resource http://www.aptest.com/resources.html Also the following list some code coverage tools specific to each language http://en.wikipedia.org/wiki/Code_coverage. In short, QA experience is developed understanding the whole domain, using a lot of tools to know when to try what and be not afraid to write scripts to automate for your custom needs. – fkl Sep 05 '12 at 18:29