57 TEST_CASE(
"TEST_CASE: Name and tags",
"[hide][tutorial]" ) {
63 TEST_CASE(
"TEST_CASE: Name, description and tags",
"Description. [hide][tutorial]" ) {
78 TEST_CASE(
"ASSERTIONS: Natural expressions",
"[hide][tutorial]" ) {
82 int a = 1, b = a, c = 2;
89 REQUIRE_FALSE( a == c);
93 TEST_CASE(
"ASSERTIONS: Exceptions",
"[hide][tutorial]" ) {
95 REQUIRE_THROWS(
throw std::exception());
96 CHECK_THROWS(
throw std::exception());
99 REQUIRE_THROWS_AS(
throw std::exception(), std::exception);
100 CHECK_THROWS_AS(
throw std::exception(), std::exception);
104 REQUIRE_NOTHROW( a == b);
105 CHECK_NOTHROW( a == b);
108 TEST_CASE(
"ASSERTIONS: Matcher expressions: Equals",
"[hide][tutorial]" ) {
109 CHECK_THAT(
"1", Equals(
"1"));
110 REQUIRE_THAT(
"1", Equals(
"1"));
113 TEST_CASE(
"ASSERTIONS: Matcher expressions: Contains",
"[hide][tutorial]" ) {
114 CHECK_THAT(
"onion", Contains(
"io"));
115 REQUIRE_THAT(
"onion", Contains(
"io"));
118 TEST_CASE(
"ASSERTIONS: Matcher expressions: StartsWith",
"[hide][tutorial]" ) {
119 CHECK_THAT(
"the start", StartsWith(
"the"));
120 REQUIRE_THAT(
"the start", StartsWith(
"the"));
123 TEST_CASE(
"ASSERTIONS: Matcher expressions: EndsWith",
"[hide][tutorial]" ) {
124 CHECK_THAT(
"the end", EndsWith(
"end"));
125 REQUIRE_THAT(
"the end", EndsWith(
"end"));
133 TEST_CASE (
"Float vs double precision",
"[hide][tutorial]") {
137 approx.epsilon(0.01);
139 float f_number = 0.1;
140 double d_number = 0.1;
141 CHECK_FALSE( f_number == d_number);
142 CHECK( f_number == Approx(d_number));
153 std::string info =
" logged.";
154 INFO(
"The info is " << info);
158 std::string warning =
" not important at all.";
159 WARN(
"The warning is " << warning);
164 std::string failure =
" not a failure at all, it is supposed to fail.";
165 FAIL(
"The failure is " << failure);
168 TEST_CASE(
"LOGGING: SCOPED_INFO",
"[hide][tutorial]" ) {
169 std::string scoped_info =
" will only be logged if a test fails in the current scope.";
170 SCOPED_INFO(
"The scoped info is " << scoped_info);
175 CAPTURE( theAnswere );
185 SCENARIO(
"BDD scenario",
"Behavior-driven development scenario. [hide][tutorial][BDD]"){
186 GIVEN(
"we create a new std::vector"){
187 std::vector<int> vector;
189 WHEN(
"we add a int to the vector"){
191 THEN(
"we can require that the vectors lenght is 1"){
192 REQUIRE( vector.size() == 1);
194 AND_WHEN(
"we add another int to the vector"){
196 THEN(
"we can require that the vectors lenght is 2"){
197 REQUIRE( vector.size() == 2);
200 THEN(
"we can require that the vectors lenght is still 1"){
201 REQUIRE( vector.size() == 1);
204 THEN(
"we can require that the vector is empty"){
205 REQUIRE(vector.empty());
SCENARIO("BDD scenario","Behavior-driven development scenario. [hide][tutorial][BDD]")
TEST_CASE("TEST_CASE: Name and tags","[hide][tutorial]")