xtd 0.2.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 {
32 enum class test_status {
34 not_started,
36 ignored,
38 succeed,
40 aborted,
42 failed
43 };
44
45 public:
47
50 test() = default;
55 test(const xtd::string& name, const std::function<void()>& method, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) noexcept;
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 bool aborted() const noexcept;
70
73 const xtd::string& actual() const noexcept;
74
77 xtd::time_span elapsed_time() const noexcept;
78
81 const xtd::string& expect() const noexcept;
82
85 bool failed() const noexcept;
86
89 bool ignored() const noexcept;
90
93 bool not_started() const noexcept;
94
97 bool succeed() const noexcept;
98
101 const xtd::diagnostics::stack_frame stack_frame() const noexcept;
102
105 const xtd::date_time& start_time() const noexcept;
106
109 std::function<void()> method() const noexcept;
110
113 const xtd::string& message() const noexcept;
114
117 const xtd::string& name() const noexcept;
118
121 const xtd::string& user_message() const noexcept;
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 static test& current_test();
134 static const test_class& current_test_class();
135 static const unit_test& current_unit_test();
136 static bool has_current_test();
137 static bool has_current_test_class();
138 static bool has_current_unit_test();
139
140 void run(const xtd::tunit::unit_test& unit_test, const xtd::tunit::test_class& test_class);
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 text as a sequence of character units.
Definition basic_string.hpp:79
Represents an instant in time, typically expressed as a date and time of day.
Definition date_time.hpp:85
Provides information about a xtd::diagnostics::stack_frame, which represents a function call on the c...
Definition stack_frame.hpp:47
static stack_frame current(const xtd::source_location &value=xtd::source_location::current()) noexcept
Crates a new xtd::diagnostics::stack_frame object corresponding to the location of the call site.
The assert class contains a collection of static methods that implement the most common assertions us...
Definition assert.hpp:30
The base class for assert.
Definition base_assert.hpp:29
Represents a test class.
Definition test_class.hpp:39
Represents a test method.
Definition test.hpp:29
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.
test()=default
Creates a new test instance.
The unit_test class is unit test base interface.
Definition unit_test.hpp:28
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
@ ignored
Test is ignored.
intmax_t intptr
Represent a pointer or a handle.
Definition intptr.hpp:23
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.hpp:10
Represents a time interval.
Definition time_span.hpp:29
Contains xtd::tunit::assert class.