1 year ago
#142799
Tim Chen
Does SECTION run at the same time in Unit testing C++(catch2)?
I am new to C++ and I am learning Unit testing using catch2. I am writing a testcase like this
TEST_CASE("Sandwich::AddTopping test", "[AddTopping]") {
// your tests for Sandwich::AddTopping here
Sandwich newsandwich;
SECTION("adding two cheese") {
newsandwich.AddTopping("cheese");
REQUIRE(newsandwich.AddTopping("cheese") == false);
}
SECTION("adding more than 5 toppings") {
newsandwich.AddTopping("cheese");
newsandwich.AddTopping("lettuce");
newsandwich.AddTopping("tomato");
newsandwich.AddTopping("onions");
newsandwich.AddTopping("pickles");
REQUIRE(newsandwich.AddTopping("cheese") == false);
}
SECTION("adding 2 other toppings") {
newsandwich.AddTopping("lettuce");
REQUIRE(newsandwich.AddTopping("lettuce"));
}
SECTION("adding in range") { REQUIRE(newsandwich.AddTopping("lettuce")); }
}
However, my code only create one Sandwich object at the beginning but the output of this is the same as teh one when I create objects separately for each SECTION. Can someone tell me why? Thank you~
c++
unit-testing
catch2
0 Answers
Your Answer