78 TEST_CASE(
"TEST_CASE: Name and tags",
"[hide][tutorial]" ) {
84 TEST_CASE(
"TEST_CASE: Name, description and tags",
"Description. [hide][tutorial]" ) {
99 TEST_CASE(
"ASSERTIONS: Natural expressions",
"[hide][tutorial]" ) {
103 int a = 1, b = a, c = 2;
110 REQUIRE_FALSE( a == c);
111 CHECK_FALSE( a == c);
114 TEST_CASE(
"ASSERTIONS: Exceptions",
"[hide][tutorial]" ) {
116 REQUIRE_THROWS(
throw std::exception());
117 CHECK_THROWS(
throw std::exception());
120 REQUIRE_THROWS_AS(
throw std::exception(), std::exception);
121 CHECK_THROWS_AS(
throw std::exception(), std::exception);
125 REQUIRE_NOTHROW( a == b);
126 CHECK_NOTHROW( a == b);
129 TEST_CASE(
"ASSERTIONS: Matcher expressions: Equals",
"[hide][tutorial]" ) {
130 CHECK_THAT(
"1", Equals(
"1"));
131 REQUIRE_THAT(
"1", Equals(
"1"));
134 TEST_CASE(
"ASSERTIONS: Matcher expressions: Contains",
"[hide][tutorial]" ) {
135 CHECK_THAT(
"onion", Contains(
"io"));
136 REQUIRE_THAT(
"onion", Contains(
"io"));
139 TEST_CASE(
"ASSERTIONS: Matcher expressions: StartsWith",
"[hide][tutorial]" ) {
140 CHECK_THAT(
"the start", StartsWith(
"the"));
141 REQUIRE_THAT(
"the start", StartsWith(
"the"));
144 TEST_CASE(
"ASSERTIONS: Matcher expressions: EndsWith",
"[hide][tutorial]" ) {
145 CHECK_THAT(
"the end", EndsWith(
"end"));
146 REQUIRE_THAT(
"the end", EndsWith(
"end"));
154 TEST_CASE (
"Float vs double precision",
"[hide][tutorial]") {
158 approx.epsilon(0.01);
160 float f_number = 0.1;
161 double d_number = 0.1;
162 CHECK_FALSE( f_number == d_number);
163 CHECK( f_number == Approx(d_number));
174 std::string info =
" logged.";
175 INFO(
"The info is " << info);
179 std::string warning =
" not important at all.";
180 WARN(
"The warning is " << warning);
185 std::string failure =
" not a failure at all, it is supposed to fail.";
186 FAIL(
"The failure is " << failure);
189 TEST_CASE(
"LOGGING: SCOPED_INFO",
"[hide][tutorial]" ) {
190 std::string scoped_info =
" will only be logged if a test fails in the current scope.";
191 SCOPED_INFO(
"The scoped info is " << scoped_info);
196 CAPTURE( theAnswere );
206 SCENARIO(
"BDD scenario",
"Behavior-driven development scenario. [hide][tutorial][BDD]"){
207 GIVEN(
"we create a new std::vector"){
208 std::vector<int> vector;
210 WHEN(
"we add a int to the vector"){
212 THEN(
"we can require that the vectors lenght is 1"){
213 REQUIRE( vector.size() == 1);
215 AND_WHEN(
"we add another int to the vector"){
217 THEN(
"we can require that the vectors lenght is 2"){
218 REQUIRE( vector.size() == 2);
221 THEN(
"we can require that the vectors lenght is still 1"){
222 REQUIRE( vector.size() == 1);
225 THEN(
"we can require that the vector is empty"){
226 REQUIRE(vector.empty());
SCENARIO("BDD scenario","Behavior-driven development scenario. [hide][tutorial][BDD]")
TEST_CASE("TEST_CASE: Name and tags","[hide][tutorial]")