xtd 0.2.0
Loading...
Searching...
No Matches
xtd::tunit::test_class Class Reference

Definition

Represents a test class.

Namespace
xtd::tunit
Library
xtd.tunit
Remarks
The class test_class must be the base class for all test classes defined in a test unit.
Examples
The following example shows how to use xtd::tunit::test_class class.
#include <xtd/xtd.tunit>
using namespace xtd::tunit;
namespace unit_tests {
// Used test_class_attribute<> to add unit test suit.
class test;
test_class_attribute<test> test_class_attr {"unit_tests::test"};
// The test class must be inherit from test_class class.
class test : public test_class {
// This is the method that is called 1 time before test class run.
class_initialize_attribute class_initialize_attr {"class_initialize", *this, &test::class_initialize};
static void class_initialize() {
}
// This is the method that is called 1 time after test class run.
class_cleanup_attribute class_cleanup_attr {"class_cleanup", *this, &test::class_cleanup};
static void class_cleanup() {
}
// This is the method that is called before any tests in a fixture are run.
test_initialize_attribute test_initialize_attr {"test_initialize", *this, &test::test_initialize};
static void test_initialize() {
}
// This is the method that is called after any tests in a fixture are run.
test_cleanup_attribute test_cleanup_attr {"test_cleanup", *this, &test::test_cleanup};
static void test_cleanup() {
}
test_method_attribute test_case1_attr {"test_case1", *this, &test::test_case1};
void test_case1() {
}
test_method_attribute test_case2_attr {"test_case2", *this, &test::test_case2};
void test_case2() {
}
test_method_attribute test_case3_attr {"test_case3", *this, &test::test_case3, test_state::ignored};
void test_case3() {
}
};
}
auto main() -> int {
return console_unit_test().run();
}
// This code can produce the following output :
//
// Start 3 tests from 1 test case
// Run tests:
// SUCCEED unit_tests::test.test_case1 (0 ms total)
// SUCCEED unit_tests::test.test_case2 (0 ms total)
// IGNORED test.test_case3 (0 ms total)
// Test ignored
//
// Test results:
// SUCCEED 2 tests.
// IGNORED 1 test.
// End 3 tests from 1 test case ran. (0 ms total)
This attribute is use to add cleanup class method to class test attribute.
Definition class_cleanup_attribute.hpp:21
This attribute is use to add initialize class method to class test attribute.
Definition class_initialize_attribute.hpp:21
The console_unit_test class is console unit test interface.
Definition console_unit_test.hpp:23
Represents a test class attribute.
Definition test_class_attribute.hpp:24
Represents a test class.
Definition test_class.hpp:39
Represents a test cleanup attribute.
Definition test_cleanup_attribute.hpp:21
Represents a test initialize attribute.
Definition test_initialize_attribute.hpp:17
Represents a test method attribute.
Definition test_method_attribute.hpp:23
Represents a test method.
Definition test.hpp:29
int32 run() noexcept
Runs all tests in this unit_test object and prints the result.
The tunit namespace contains a unit test library.
Definition abort_error.hpp:10
Examples
hello_world_tunit_without_helpers.cpp, and test_class_without_helpers.cpp.

Public Constructors

 test_class ()
 Creates a new test_class instance.
 

Public Properties

xtd::time_span elapsed_time () const noexcept
 Gets the elapsed time of the test class.
 
xtd::string name () const noexcept
 Gets the name of the test class.
 
size_t test_count () const noexcept
 Gets the test count.
 
size_t aborted_test_count () const noexcept
 Gets the aborted test count.
 
size_t failed_test_count () const noexcept
 Gets the failed test count.
 
size_t ignored_test_count () const noexcept
 Gets the ignored test count.
 
size_t succeed_test_count () const noexcept
 Gets the succeed test count.
 
const xtd::date_timestart_time () const noexcept
 Gets the start time of the test class.
 
const std::vector< xtd::tunit::test > & tests () const noexcept
 Gets the tests array of this test class.
 

Protected Methods

void add_class_cleanup (const xtd::tunit::test &class_cleanup) noexcept
 Adds the class cleanup method.
 
void add_class_initialize (const xtd::tunit::test &class_initialize) noexcept
 Adds the class initialize method.
 
void add_test_cleanup (const xtd::tunit::test &test_cleanup) noexcept
 Adds the test cleanup method.
 
void add_test_initialize (const xtd::tunit::test &test_initialize) noexcept
 Adds the test initialize method.
 
void add_test_method (const xtd::tunit::test &test) noexcept
 Adds a test method.
 

Constructor & Destructor Documentation

◆ test_class()

xtd::tunit::test_class::test_class ( )
inline

Creates a new test_class instance.

Member Function Documentation

◆ elapsed_time()

xtd::time_span xtd::tunit::test_class::elapsed_time ( ) const
noexcept

Gets the elapsed time of the test class.

Returns
The elapsed time of the test class.

◆ name()

xtd::string xtd::tunit::test_class::name ( ) const
noexcept

Gets the name of the test class.

Returns
The nzme of the test class.

◆ test_count()

size_t xtd::tunit::test_class::test_count ( ) const
noexcept

Gets the test count.

Returns
The test count.

◆ aborted_test_count()

size_t xtd::tunit::test_class::aborted_test_count ( ) const
noexcept

Gets the aborted test count.

Returns
The aborted test count.

◆ failed_test_count()

size_t xtd::tunit::test_class::failed_test_count ( ) const
noexcept

Gets the failed test count.

Returns
The failed test count.

◆ ignored_test_count()

size_t xtd::tunit::test_class::ignored_test_count ( ) const
noexcept

Gets the ignored test count.

Returns
The ignored test count.

◆ succeed_test_count()

size_t xtd::tunit::test_class::succeed_test_count ( ) const
noexcept

Gets the succeed test count.

Returns
The succeed test count.

◆ start_time()

const xtd::date_time & xtd::tunit::test_class::start_time ( ) const
noexcept

Gets the start time of the test class.

Returns
The start time of the test class.

◆ tests()

const std::vector< xtd::tunit::test > & xtd::tunit::test_class::tests ( ) const
noexcept

Gets the tests array of this test class.

Returns
The tests array.

◆ add_class_cleanup()

void xtd::tunit::test_class::add_class_cleanup ( const xtd::tunit::test class_cleanup)
protectednoexcept

Adds the class cleanup method.

Parameters
class_cleanupThe class cleanup method.

◆ add_class_initialize()

void xtd::tunit::test_class::add_class_initialize ( const xtd::tunit::test class_initialize)
protectednoexcept

Adds the class initialize method.

Parameters
class_initializeThe class initialize method.

◆ add_test_cleanup()

void xtd::tunit::test_class::add_test_cleanup ( const xtd::tunit::test test_cleanup)
protectednoexcept

Adds the test cleanup method.

Parameters
test_cleanupThe test cleanup method.

◆ add_test_initialize()

void xtd::tunit::test_class::add_test_initialize ( const xtd::tunit::test test_initialize)
protectednoexcept

Adds the test initialize method.

Parameters
test_initializeThe test initialize method.

◆ add_test_method()

void xtd::tunit::test_class::add_test_method ( const xtd::tunit::test test)
protectednoexcept

Adds a test method.

Parameters
testThe a test method.

The documentation for this class was generated from the following file: