Giter Site home page Giter Site logo

cpptfw's Introduction

cppTFW

Simple C++ test framework based on Qt, but not on QTest.
The framework consists of one header only and needs no compilation.

Test setup

Class tests are created by deriving a test class from QObject in a header file and defining private slots for each test case.
SomeClass_Test.h:

#include "TestFramework.h"

TEST_CLASS(SomeClass_Test)
{
Q_OBJECT
private slots:

	void TestCase1()
	{
		I_EQUAL(1+1, 2)
	}

	void TestCase2()
	{
		IS_FALSE(1+1==3)
	}
}

The execution of all test classes is executed by this simple call:
main.cpp:

#include "TestFramework.h"

int main(int argc, char *argv[])
{
	return TFW::run(argc, argv);
}

Text executable command-line parameters

The test executable can be invoked with these parameters:

  • -s Filter string for test cases. Tests that conain the string (case-sensitive) are executed.
  • -l Test case list file. Tests that are contained in the given text file are executed.
  • -h Prints a short help.

Basic comparison macros

  • IS_TRUE(expression) Checks that the expression evaluates to true.
  • IS_FALSE(expression) Checks that the expression evaluates to false.
  • I_EQUAL(actual, expected) Integer equality check.
  • F_EQUAL(actual, expected) Float equality check (with default accuracy).
  • F_EQUAL2(actual, expected, delta) Float equality ceck (with custom accuracy).
  • S_EQUAL(actual, expected) String equality check.
  • X_EQUAL(actual, expected) General equality check.
  • IS_THROWN(exception, expression) Checks that the exception type is thrown by the expression.

##File handling macros

  • EXECUTE(toolname, arguments) Executes a tool from the same folder and checks the error code.
  • EXECUTE_FAIL(toolname, arguments) Executes a tool from the same folder and ignores the error code.
  • TESTDATA(filename) Locates test data relative to the test source file.
  • REMOVE_LINES(filename, regexp) Removes lines that match the given QRegExp form a file.
  • COMPARE_FILES(actual, expected) File equality check.
  • COMPARE_GZ_FILES(actual, expected) File equality check for gzipped files.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.