Skip to content

nekenyu/JonTest

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JonTest

Demonstration C++ Unit Test Library

See also:

Note

This page duplicates the doxygen main page.

Introduction

JonTest is a rapid demonstration of certain techniques for the benefit of a particular person. Given that it functioned, it is presented as a modern example of the author's (rushed) work.

Warning

This is not intended for production work.

  • Genreal coding standards conventions are violated out of necessity and convenience to the user of this tool. For example:
    • Macro functions are used to facilitate reporting of filename and line number.
  • The author did not create this to be used and maintained.
    • Better alternatives exist, such as boost test and google test exist.
    • Use them.
  • Extensive real-world testing has not been performed.

This is a unit test tool providing the following:

  • Minimial boilerplate for individual test suites and cases
  • single definition within a .cpp file
  • automatic test suite and case registration
  • General assertions based around:
    • boolean values
    • pointer nullptr / valid (non-nullptr)
    • numeric-style comparison: == != < <= > >=
    • specific exception class (including base class) thrown
    • assertions that are known to fail
  • Expected Failures of asserts can be defined:
    • Failing each contained assert will pass the test.
    • If all contained asserts pass, the expected failure will then fail the test.

This is constrained by the following:

  • The build system only has GNU Make definitions to build under a GNU environment using g++.
  • The build system is only configured for --std=c++23

Overview

The TestRunne::get() singleton is used to run tests. Typically, this is from a main() function; however, it could be integrated into a larger testing system.

See also:

Testing is organized a tree containing:

  • Test Suites created with TEST_SUITE(suiteName), containing:
    • (Optional) Reusable Test Case data, unique for each Test Suite that is:
      • Located in the class generated by/between TEST_SUITE(suitName) ... TEST_SUITE_END()
      • (Optional) Initialized before each test case by the automatically run setup() { ... }
      • Used in each Test Case method generated by TEST_CASE(caseName) { ... }
      • (Optional) Cleaned up after each test case by the automatically run teardown()
    • (Optional) Test Case setup(), unique for each Test Suite, run before each Test Case in the Test Suite, which may contain:
      • Assertions of validatity, such as assert()
    • Test Cases created with TEST_CASE(caseName), verified by/containing:
      • Assertions of validatity, such as assert()
    • (Optional) Test Case teardown(), unique for each Test Suite, run before after Test Case in the Test Suite, which may contain:
      • Assertions of validatity, such as assert()

Source Code Examples

See also:

Primary header files:

  • TestSuite.h -- Defines TEST_SUITE()s and TEST_CASE()s
  • Assert.h -- Defines assert()ions of many forms
  • TestRunner.h -- Defines the JonTest::TestRunner to run all the tests
  • Logger.h -- Defines the JonTest::Logger interface, and the common JonTest::StreamLogger

See also:

About

Demonstration C++ Unit Test Library

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published