Läuft SECTION gleichzeitig im Unit-Testing von C++ (catch2)?C++

Programme in C++. Entwicklerforum
Guest
 Läuft SECTION gleichzeitig im Unit-Testing von C++ (catch2)?

Post by Guest »

Ich bin neu in C++ und lerne Unit-Tests mit Catch2. Ich schreibe einen Testfall wie diesen

Code: Select all

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")); }
}
Mein Code erstellt jedoch am Anfang nur ein Sandwich-Objekt, aber die Ausgabe ist dieselbe wie die, wenn ich Objekte für jeden ABSCHNITT separat erstelle. Kann mir jemand sagen warum? Danke~

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post