-
-
Notifications
You must be signed in to change notification settings - Fork 59
Description
I see the Catch2 GENERATE macro as something similar to pytest.paramertize decorator.
In the VS Code python test view, each set of parameters is identified as a separate test and can be run or debugged separately. This is very handy.
Is this something that TestMate can also do with Catch2 GENERATE (or other test frameworks that can have a set of different test data for the same test)?
I note that Catch2 SECTION statement does get presented with a tree style hierarchy. I was expecting something similar with GENERATE. i.e. an expand/collapse icon and list of tests with the combinations of inputs.
Maybe my understanding of GENERATE macro is incorrect, or my expectations are incorrect, or maybe my test code is not written appropriately?
#include <catch2/catch_test_macros.hpp>
#include <catch2/generators/catch_generators.hpp>
#include <catch2/generators/catch_generators_range.hpp>
TEST_CASE("BJS nested test 1", "[foo]")
{
int x = GENERATE(range(1, 5));
int y = GENERATE(range(6, 9));
REQUIRE(true);
}
TEST_CASE("BJS nested test 2", "[foo]")
{
SECTION("section 1") {
REQUIRE(true);
SECTION("section 2") {
REQUIRE(true);
SECTION("section 3") {
REQUIRE(true);
}
}
}
}This C++ test case from the Catch2 examples (slightly modified for C++23) does not show the input data in the vsdcode test tab.
TEST_CASE("Table allows pre-computed test inputs and outputs", "[example][generator]") {
SECTION("This section is run for each row in the table") {
auto [test_input, expected_output] =
GENERATE(table<std::string, size_t>(
{
{ "one", 3 },
{ "two", 3 },
{ "three", 5 },
{ "four", 4 },
} ) );
CAPTURE(test_input, expected_output);
// run the test
auto result = expected_output;
// check it matches the pre-calculated data
REQUIRE(result == expected_output);
}
}The equivalent Python Pytest test code, does show the list of inputs in vscode test tab and each test input can be run or debugged individually
import pytest
class Test_BJS:
@pytest.mark.parametrize(
'test_input,expected_output',
[
( "one", 3 ),
( "two", 3 ),
( "three", 5 ),
( "four", 4 ),
]
)
def test_table_data(self, test_input:str, expected_output:int):
# run the test
result = expected_output
# check it matches the pre-calculated data
assert result == expected_output
