Questions tagged [catch2]

Catch is a unit testing framework for C++

Catch2 offers a BDD syntax, fixtures, Matchers and dynamic data-generation, and a simplified syntax using overloaded assertions. Catch2 is designed for simplicity – it is released as a single include file and allows the use of natural C++ expressions inside assertions.

Catch2 is hosted on GitHub, available at catch-lib.net, and is openly discussed in a Google group.

153 questions
1
vote
0 answers

Running a test for every file in a directory, dynamically

I have an application written in C++, configured with CMake, tested using Catch2, the tests are invoked through CTest. I have a fairly large list of files that each contain captures of messages that have caused an issue in my application in the…
David Stone
  • 26,872
  • 14
  • 68
  • 84
1
vote
1 answer

How to add parameters to section names in Catch2

I'm using Catch2 to create a set of tests for some C++ legacy code and I have a function that I would like to test for a good amount of values. I have found that I can use the GENERATE keyword to create a data generator variable that will repeat the…
Shunya
  • 2,344
  • 4
  • 16
  • 28
1
vote
0 answers

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…
Tim Chen
  • 55
  • 4
1
vote
1 answer

How do I use catch2 just by cloning its repository and copying its src to my project?

I am trying to get catch2 running for a barebone project just to get familiar with it but so far I failed installing it in whatever sense possible. the catch2-git repository either points you to installing it together with cmake (via vcpkg (I cannot…
jkbs1337
  • 53
  • 6
1
vote
1 answer

Run all catch2 tests in one compile unit without tag definition

I have the following project structure: test_main.cc #define CATCH_CONFIG_MAIN #include "catch2.hpp" test1.cc #include "catch2.hpp" TEST_CASE("test1", "[test1]") { REQUIRE(1 == 1); } test2.cc #include "catch2.hpp" TEST_CASE("test2",…
schorsch312
  • 5,553
  • 5
  • 28
  • 57
1
vote
1 answer

Approximation using gmp mpf_class

I am writing a UnitTest using Catch2. I want to check if two vectors are equal. They look like the following using gmplib: std::vector result Due to me 'faking' the expected_result vector, I get the following message after a failed…
Tom
  • 100
  • 1
  • 9
1
vote
1 answer

Printing failed test case names in Catch2

I have a relatively huge number of test cases. In case of failure, it takes time to go through all the log files and find the failed test cases. Is there any way in Catch2 to print the failed test cases?
Emiliano
  • 79
  • 8
1
vote
1 answer

Is there a Catch2 variable that provides the name of the current test?

I'm using Catch2 for unit tests and I would like to know the name of a C++ or environment variable that reveals the name of the current test that is executing. Is there a way to do this, or is it bad form to have the test debugging code print the…
vy32
  • 28,461
  • 37
  • 122
  • 246
1
vote
1 answer

How to best make my catch2 CHECK() output more informative about what it checks?

I am working on some code with unit tests using catch2 (and it will stay that way, for reasons). Now, in the set of unit tests, there are a lot of (pairs of) lines which look like this: T t1; t1 = foo(some, params, here); CHECK(my_compare(t1,…
einpoklum
  • 118,144
  • 57
  • 340
  • 684
1
vote
1 answer

How can I enable crash dumps in Catch2 C++ tests in Azure DevOps CI/CD pipeline?

I'm developing a C++ software product for Windows. I wrote tests for it using the Catch2 framework. They are automated in CI/CD pipeline in Azure Dev Ops (ADO). What I would like to do is to get a crash dump (.dmp file) automatically created and…
Darren Cohen
  • 126
  • 6
1
vote
2 answers

Catch2 test don't work when building application with CMake

I'm trying to test my program by using Catch2 tests and build the application using CMake. The program works and the application gets build when the Catch2 tests are not implemented. Once I implemented the Catch2 tests, the application won't build…
fel1-xd
  • 21
  • 1
  • 3
1
vote
1 answer

Catch2 linker errors

I've added Catch2 as a submodule to my project and included the Catch2/include/catch.hpp header using the following code: testmain.cpp: #define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file #include…
uliwitness
  • 8,532
  • 36
  • 58
1
vote
0 answers

How to pre-build a library in CMake

I have been learning CMake and am having persistent build issues with the library Catch2. I am using Qt as my IDE and have downlaoded Qt6 and MinGW 8 via the Qt maintainance tool. My issue seems to be that during compilation my test/main.cpp, which…
Troyseph
  • 4,960
  • 3
  • 38
  • 61
1
vote
2 answers

How does the Catch2 GENERATE macro work internally?

Recently I learned about the GENERATE macro in Catch2 (from this video). And now I am curious about how it works internally. Naively one would think that for a test case with k generators (by a generator I mean one GENERATE call site), Catch2 just…
ph3rin
  • 4,426
  • 1
  • 18
  • 42
1
vote
1 answer

Catch2 - Populating singleton with different mock data for different test files

I am using Catch2 for unit testing in my C++ project. I have a singleton class and it is being used in different test files. For example one file might be testing the singleton itself, and another file testing the interaction between the singleton…
Kenneth
  • 13
  • 3