xtd 0.2.0
test.h
Go to the documentation of this file.
1 #pragma once
5 #include "../tunit_export.h"
6 #include "assert.h"
7 #include "assert_error.h"
8 #include <xtd/diagnostics/stack_frame>
9 #include <xtd/date_time>
10 #include <xtd/using>
11 #include <functional>
12 
14 namespace xtd {
16  namespace tunit {
18  class test_class;
19  class unit_test;
20  class valid;
22 
31  class tunit_export_ test final {
34  enum class test_status {
36  not_started,
38  ignored,
40  succeed,
42  aborted,
44  failed
45  };
46 
47  public:
49 
52  test() = default;
57  test(const xtd::ustring& name, const std::function<void()>& method, const xtd::diagnostics::stack_frame& stack_frame) noexcept;
63  test(const xtd::ustring& name, const std::function<void()>& method, bool ignore, const xtd::diagnostics::stack_frame& stack_frame) noexcept;
65 
67 
71  bool aborted() const noexcept;
72 
75  const xtd::ustring& actual() const noexcept;
76 
79  std::chrono::milliseconds elapsed_time() const noexcept;
80 
83  const xtd::ustring& expect() const noexcept;
84 
87  bool failed() const noexcept;
88 
91  bool ignored() const noexcept;
92 
95  bool not_started() const noexcept;
96 
99  bool succeed() const noexcept;
100 
103  const xtd::diagnostics::stack_frame stack_frame() const noexcept;
104 
107  const xtd::date_time& start_time() const noexcept;
108 
111  std::function<void()> method() const noexcept;
112 
115  const xtd::ustring& message() const noexcept;
116 
119  const xtd::ustring& name() const noexcept;
120 
123  const xtd::ustring& user_message() const noexcept;
125 
127  static intptr __internal_tunit_unit_tests_mode__;
129 
130  private:
131  friend class xtd::tunit::assert;
132  friend class xtd::tunit::base_assert;
133  friend class xtd::tunit::test_class;
134  friend class xtd::tunit::valid;
135  static test& current_test();
136  static const test_class& current_test_class();
137  static const unit_test& current_unit_test();
138  static bool has_current_test();
139  static bool has_current_test_class();
140  static bool has_current_unit_test();
141 
143 
144  xtd::date_time end_time_point;
145  static test* current_test_;
146  static const test_class* current_test_class_;
147  static const unit_test* current_unit_test_;
148  xtd::ustring actual_;
149  xtd::ustring expect_;
151  xtd::ustring message_;
152  std::function<void()> method_;
153  xtd::ustring name_;
154  xtd::date_time start_time_;
155  test_status status_ = test_status::not_started;
156  xtd::ustring user_message_;
157  };
158  }
159 }
The base class for assert.
Definition: base_assert.h:29
intmax_t intptr
Represent a pointer or a handle.
Definition: types.h:151
Represents a test method.
Definition: test.h:31
The assert class contains a collection of static methods that implement the most common assertions us...
Definition: assert.h:36
Contains xtd::tunit::assert_error exception.
The xtd namespace contains all fundamental classes to access Hardware, Os, System, and more.
Definition: system_report.h:17
Represents text as a sequence of UTF-8 code units.
Definition: ustring.h:46
Represents a test class.
Definition: test_class.h:39
Represents an instant in time, typically expressed as a date and time of day.
Definition: date_time.h:78
Provides information about a xtd::diagnostics::stack_frame, which represents a function call on the c...
Definition: stack_frame.h:37
static stack_frame empty() noexcept
Return an empty stack frame.
Contains xtd::tunit::assert class.
The valid class contains a collection of static methods that implement the most common assertions use...
Definition: valid.h:22
The unit_test class is unit test base interface.
Definition: unit_test.h:35