I am a professional web developer and therefore I'm used to using very high-level scripting languages and testing tools. I've recently been working, personally, more with C and writing many C programs for unix-based systems to do various tasks.
However, I still haven't gotten into a good groove for unit testing this code and I was wondering what tools C programmers use to create automated tests to verify code.
A unit is the smallest testable part of an application. Unit tests assess code in isolation. In C++ this means writing tests for methods or functions. Tests only examine code within a single object.
To unit test your code, you need a unit testing framework. A unit testing framework is a library of classes and methods that help you write unit tests. There are many unit testing frameworks available, but the most popular ones for C# development are: xUnit – xUnit is a unit test framework for C#.
Writing unit tests for code means writing code that can be broken down into discrete units. Testable code is modular because discretely tested units are loosely coupled. If this reason for unit testing, combined with the previous one, reads like an advertisement for test-driven development (TDD), that’s because they are.
The most basic unit test verifies that the code behaves as expected when given specific inputs. For example, you might have a unit test that checks if a function returns the correct value when given an input string. More complex unit tests can verify that several code units work together as intended. What is a unit testing framework?
Consider using CppUTest. It is written in C++, but hides the C++ so that C programmers can ignore the C++.
Unity is a C-only test harness that is good too. It uses ruby to generate test runners.
I'd stay clear of CppUnit. It requires C++ knowledge and each test has to be individually installed.
James
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With