|
benchtest
Benchmark and testing framework for C++
|
Benchmarking and testing framework. More...
|
Modules | |
| assertions | |
| Macros for expectations and assertions. | |
Classes | |
| class | testing::Test |
| Abstract class to be inherited by test fixtures. More... | |
Macros | |
| #define | TEST(test_case_name, test_name) |
| Declare an inline test. More... | |
| #define | TEST_F(test_fixture, method_name) |
| Declare a test using a fixture. More... | |
| #define | TEST_T(test_fixture, type_name, method_name) |
| Declare a test using a fixture template. More... | |
Functions | |
| template<typename T > | |
| void | testing::PrintTo (const T &val,::std::ostream *os) |
| Specialized printer for testing results. More... | |
| template<typename T > | |
| ::std::string | testing::PrintToString (const T &val) |
Prints val to a string using PrintTo(). | |
| static void | testing::Test::SetUpTestCase () |
| Called once before any tests in this case are run. | |
| static void | testing::Test::TearDownTestCase () |
| Called once when all tests in this case are finished. | |
| virtual void | testing::Test::SetUp () |
| Called at the start of every test using this fixture. | |
| virtual void | testing::Test::TearDown () |
| Called at the end of every test using this fixture. | |
| bool | testing::Test::Benchmark (unsigned int max=100) |
| Controls execution of a benchmarked section. More... | |
| template<bool = true> | |
| class Reporter * | testing::reporter (class Reporter *newr=nullptr) |
| Select which Reporter to use. | |
| int | testing::run () |
| Run the tests. Returns an exit status. | |
Benchmarking and testing framework.
The benchtest framework may be used to test your own applications. Usage and syntax is similar, but not 100% compatible, to the Google C++ Testing Framework.
Setting up a new project to test is very easy. Make sure the benchtest include directory is in your compiler include path. Then call the test runner in main(). It is important to return from main() with the result of run(). This is because any testing automation, like continuous integration, depends on the exit status to determine if any failures were encountered.
A test run consists of test cases that have one or more tests that have expectations, assertions, and benchmarks.
| #define TEST | ( | test_case_name, | |
| test_name | |||
| ) |
| #define TEST_F | ( | test_fixture, | |
| method_name | |||
| ) |
Declare a test using a fixture.
Fixtures can be used when you have a number of tests that operate on similar data.
| #define TEST_T | ( | test_fixture, | |
| type_name, | |||
| method_name | |||
| ) |
Declare a test using a fixture template.
A fixture template makes it easier to test code written to work with multiple data types or classes. For example, parts of a dsp library are tested using both float and double types.
| void testing::PrintTo | ( | const T & | val, |
| ::std::ostream * | os | ||
| ) |
Specialized printer for testing results.
This function is used to print the value of a type in failure reports. If the type already supplies an operator<< to ::std::ostream it is used by default. It may not be possible to use operator<< or you may consider it bad form to do so only for testing. In that case, specialize this function to print your value.
|
inlineprotected |
Controls execution of a benchmarked section.
| max | Limit the maximum number of executions. |
| bool | True indicates the benchmarked section should execute again. |
A test may include a single benchmark.
The benchmarked section will run a minimum number of times equal to 20% of max. It will continue to run until the max limit is hit or faster executions are not being found. Regardless of max, at least 5 iterations will be run. If you have a very slow algorithm, decreasing max can guard against accidentally long run times when tests are deployed to be run automatically, such as on a continuous integration server.
If you have a very fast algorithm, the timer may not provide enough resolution for good results. In this case it's usually easy to run a set to reduce the timer variance. However, consider that you may be testing too small of a work unit which will report unrealistic results because it would normally be inlined by the compiler or is strongly affected by memory caching.
1.8.9.1