Friday, February 13, 2026

With the framework CppUTest how can I execute just some assessments?


I am tryng to make use of the C/C++ framework CppUTest to develop my C code by TDD.
I’ve put in CppUTest in my system within the folder /path/to/cpputest.

Pattern supply code

To elucidate my downside I’ve written the next pattern code within the folder /path/to/cpputest-example.

The adopted is a file referred to as test_01.cpp. It comprises 3 instance assessments:

#embody "CppUTest/TestHarness.h"

TEST_GROUP(FirstTestGroup) {
};

TEST(FirstTestGroup, Test01) {
   FAIL("Fail me!");
}

TEST(FirstTestGroup, Test02) {
    STRCMP_EQUAL("whats up", "world");
}

TEST(FirstTestGroup, Test03) {
    STRCMP_EQUAL("whats up", "whats up");
}

After that I’ve written the file AllTest.cpp which comprises the predominant() perform for executing all assessments:

#embody "CppUTest/CommandLineTestRunner.h"

int predominant(int ac, char** av) {
    return CommandLineTestRunner::RunAllTests(ac, av);
}

The Makefile

After that, all the time within the folder /path/to/cpputest-example, I’ve created the adopted Makefile:

# The compiler: gcc for C program, outline as g++ for C++
#CC = gcc
CC = g++

# compiler flags:
#  -g     - this flag provides debugging info to the executable file
#  -Wall  - this flag is used to activate most compiler warnings
CFLAGS  = -g -Wall


CPPUTEST_HOME = /path/to/cpputest

CPPFLAGS += -I$(CPPUTEST_HOME)/embody

LD_LIBRARIES = -L$(CPPUTEST_HOME)/lib -lCppUTest -lCppUTestExt


# The construct goal 
TARGET = AllTests

$(TARGET): AllTests.o test_01.o
    $(CC) $(CPPFLAGS) $(CXXFLAGS) $(CFLAGS) -o AllTests AllTests.o test_01.o $(LD_LIBRARIES)
    
AllTests.o: AllTests.cpp
    $(CC) $(CPPFLAGS) $(CXXFLAGS) $(CFLAGS) $(LD_LIBRARIES) -c AllTests.cpp

test_01.o: test_01.cpp
    $(CC) $(CPPFLAGS) $(CXXFLAGS) $(CFLAGS) $(LD_LIBRARIES) -c test_01.cpp

clear:
    $(RM) *.o $(TARGET)

Compile and execution of all assessments

To compile all assessments and create the executable file AllTests I’ve executed the command make within the folder which comprises the Makefile:

> cd /path/to/cpputest-example

> make

The execution of all assessments is acquire by the command line:

> /path/to/cpputest-example/AllTests

The file is executed with success and a couple of assessments fail (the primary and the second), whereas the third is executed with success.

My query

In an actual mission I’ve many assessments so the output of their execution it is extremely lengthy and never clear. I wish to execute solely a number of the assessments and never all.
How can I execute solely a number of the assessments and never all?

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles

PHP Code Snippets Powered By : XYZScripts.com