Skip to content

A quick example on how to run unit tests with CppUTest

License

Notifications You must be signed in to change notification settings

StepUp-Solutions/CppUTest-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CppUTest template

Unit testing

Goal : test separately every feature

  • Test scenario (check sum() function)
  • Test case (works with 2 positive numbers)
  • Preconditions (C std lib works)
  • Test steps (Create 2 variables, call sum(), check the result)
  • Test data (a=1, b=2)
  • Expected result (return value = 3)

Installing CppUTest from source code

Dependencies : autoconf, automake, lcov

sudo apt install autoconf automake lcov
./setup-cpputest.sh

If you want to force download of CppUTest, use ./setup-cpputest.sh -reinstall.

If you want to uninstall CppUTest, use ./setup-cpputest.sh -uninstall.

CppUTest using MakefileWorker

After writing configuration in MakeTests.mk, run the following commands:

Only run the tests

make tests

or

make all

Generate coverage report

make tests_coverage

Generate coverage HTML files (source files must be in the working folder)

Clean

make clean

Using CppUTest without MakefileWorker

First install cpputest package:

sudo apt install cpputest

Then complete and run this C++ example (can de done in Eclipse):

#include <CppUTest/CommandLineTestRunner.h>
#include <CppUTest/TestHarness.h>

TEST_GROUP(Group) {};

TEST(Group, Test) {};

int main(int argc, char ** argv)
{
    RUN_ALL_TESTS(argc, argv);
}

Useful ressources:

License

This repository is licensed under the MIT License - see the LICENSE file for details

Acknowledgements

A huge thank you to Charles Gayot for letting me opensource this repository ! ❤️

About

A quick example on how to run unit tests with CppUTest

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published