xtd 1.0.0
Loading...
Searching...
No Matches
test.hpp
Go to the documentation of this file.
1
4#pragma once
5#include "../tunit_export.hpp"
6#include "assert.hpp"
7#include "assert_error.hpp"
8#include <xtd/diagnostics/stack_frame>
9#include <xtd/date_time>
10
12namespace xtd {
14 namespace tunit {
16 class test_class;
17 class unit_test;
18 class valid;
20
29 class tunit_export_ test final : public xtd::object {
32 enum class test_status {
36 ignored,
38 succeed,
40 aborted,
42 failed
43 };
44
45 public:
47
50 test() = default;
61 test(const xtd::string& name, const std::function<void()>& method, bool ignore, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) noexcept;
63
65
69 [[nodiscard]] auto aborted() const noexcept -> bool;
70
73 [[nodiscard]] auto actual() const noexcept -> const xtd::string&;
74
77 [[nodiscard]] auto elapsed_time() const noexcept -> xtd::time_span;
78
81 [[nodiscard]] auto expect() const noexcept -> const xtd::string&;
82
85 [[nodiscard]] auto failed() const noexcept -> bool;
86
89 [[nodiscard]] auto ignored() const noexcept -> bool;
90
93 [[nodiscard]] auto not_started() const noexcept -> bool;
94
97 [[nodiscard]] auto succeed() const noexcept -> bool;
98
101 [[nodiscard]] auto stack_frame() const noexcept -> const xtd::diagnostics::stack_frame&;
102
105 [[nodiscard]] auto start_time() const noexcept -> const xtd::date_time&;
106
109 [[nodiscard]] auto method() const noexcept -> std::function<void()>;
110
113 [[nodiscard]] auto message() const noexcept -> const xtd::string&;
114
117 [[nodiscard]] auto name() const noexcept -> const xtd::string&;
118
121 [[nodiscard]] auto user_message() const noexcept -> const xtd::string&;
123
125 static intptr __internal_tunit_unit_tests_mode__;
127
128 private:
129 friend class xtd::tunit::assert;
130 friend class xtd::tunit::base_assert;
131 friend class xtd::tunit::test_class;
132 friend class xtd::tunit::valid;
133 [[nodiscard]] static auto current_test() -> test&;
134 [[nodiscard]] static auto current_test_class() -> const test_class&;
135 [[nodiscard]] static auto current_unit_test() -> const unit_test&;
136 [[nodiscard]] static auto has_current_test() -> bool;
137 [[nodiscard]] static auto has_current_test_class() -> bool;
138 [[nodiscard]] static auto has_current_unit_test() -> bool;
139
140 auto run(const xtd::tunit::unit_test& unit_test, const xtd::tunit::test_class& test_class) -> void;
141
142 xtd::date_time end_time_point_;
143 static test* current_test_;
144 static const test_class* current_test_class_;
145 static const unit_test* current_unit_test_;
146 xtd::string actual_;
147 xtd::string expect_;
148 xtd::diagnostics::stack_frame stack_frame_ = null;
149 xtd::string message_;
150 std::function<void()> method_;
151 xtd::string name_;
152 xtd::date_time start_time_;
153 test_status status_ = test_status::not_started;
154 xtd::string user_message_;
155 };
156 }
157}
Contains xtd::tunit::assert_error exception.
Represents an instant in time, typically expressed as a date and time of day.
Definition date_time.hpp:83
Provides information about a xtd::diagnostics::stack_frame, which represents a function call on the c...
Definition stack_frame.hpp:46
static auto current(const xtd::diagnostics::source_location &value=xtd::diagnostics::source_location::current()) noexcept -> xtd::diagnostics::stack_frame
Crates a new xtd::diagnostics::stack_frame object corresponding to the location of the call site.
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.hpp:45
Represents a time interval.
Definition time_span.hpp:29
Represents a test class.
Definition test_class.hpp:39
auto not_started() const noexcept -> bool
Get a value that represent a not started test.
auto failed() const noexcept -> bool
Gest a value that represent an failed test.
auto aborted() const noexcept -> bool
Gets a value that represent an aborted test.
auto start_time() const noexcept -> const xtd::date_time &
Gets the start time of the test method.
auto elapsed_time() const noexcept -> xtd::time_span
Gets the elapsed time of the test method.
test(const xtd::string &name, const std::function< void()> &method, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current()) noexcept
Creates a new test instance with specified name, method and stack frame.
auto succeed() const noexcept -> bool
Gets a value that represent an succeed test.
auto expect() const noexcept -> const xtd::string &
Gets the expect value string.
auto method() const noexcept -> std::function< void()>
Gets the test method.
auto stack_frame() const noexcept -> const xtd::diagnostics::stack_frame &
Gets the stack frame of the test method.
auto ignored() const noexcept -> bool
Get a value that represent an ignored test.
auto actual() const noexcept -> const xtd::string &
Gets the actual value string.
test()=default
Creates a new test instance.
auto message() const noexcept -> const xtd::string &
Gets the message.
auto name() const noexcept -> const xtd::string &
Gets the name of the test method.
auto user_message() const noexcept -> const xtd::string &
Gets the user message.
The unit_test class is unit test base interface.
Definition unit_test.hpp:30
The valid class contains a collection of static methods that implement the most common assertions use...
Definition valid.hpp:22
#define tunit_export_
Define shared library export.
Definition tunit_export.hpp:13
xtd::basic_string< char > string
Represents text as a sequence of UTF-8 code units.
Definition __string_definitions.hpp:43
null_ptr null
Represents a null pointer value.
std::intmax_t intptr
Represent a pointer or a handle.
Definition intptr.hpp:23
The xtd::diagnostics namespace provides classes that allow you to interact with system processes,...
Definition assert_dialog_result.hpp:10
The tunit namespace contains a unit test library.
Definition abort_error.hpp:10
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition abstract_object.hpp:8
Contains tunit_export_ keyword.
Contains xtd::tunit::assert class.