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
3
votes
1 answer

How to perform code coverage in C++ using meson?

I'm using meson and ninja as build system in my C++ project and I've configured catch2 as testing framework. I was wondering how to perform code coverage with the tests that I've written. I read this page, https://mesonbuild.com/Unit-tests.html…
Antonio La Marra
  • 5,949
  • 4
  • 15
  • 23
3
votes
1 answer

Catch2 unit tests are not running with CMake project

I have a project structured like: |--assets/ |--core/ |--deps/ |--Catch2/ |--win32/ |--# Have Catch2 library installed here |--include/ |--# Nothing here |--src/ |--sample.cpp # No…
kovac
  • 4,945
  • 9
  • 47
  • 90
3
votes
1 answer

How can I use Catch2 to test my CMake static library project?

I'm writing a static library which contains some shared code between several projects. In order to verify that the code in this library functions properly I'd like to use Catch2 to do some unit testing on it. Unfortunately, when attempting to run…
Bartvbl
  • 2,878
  • 3
  • 28
  • 45
3
votes
4 answers

How to set up Catch2 in Bazel project

I have started a simple C++ project that uses Bazel as build system and would like to add Catch2 to it, as test framework. This is what my project looks like so far: WORKSPACE -> empty file src/ Money.hpp Money.cpp BUILD where BUILD is…
Martinsos
  • 1,663
  • 15
  • 31
2
votes
1 answer

Catch2: Checking if result is 0.0 with a relative error fails

I'm using Catch2 to check the result of a floating point calculation. It fails with the message: Failure: REQUIRE_THAT(quat.R_component_1(), Catch::WithinRel(0.0f, ALLOWED_RELATIVE_ERROR)) with expansion: 0.0 and 0 are within 0.01% of each…
Chris F
  • 23
  • 5
2
votes
0 answers

catch2 run all untagged tests plus hidden ones with specific tags

I'm trying to tag all tests that send real network requests with [.network] so that they don't run by default. My hope was that I could optionally include them to be ran in addition to all my untagged tests; but I have not been able to figure out…
2
votes
0 answers

CMake does not display trace of compile error

I'm currently developing a fairly large library dependent on other libraries (Eigen, Catch2, and Kokkos), and use CMake for building and linking everything. Because so much is going on, it's difficult to use a MWE here or give a lot of detail, but…
Danny
  • 31
  • 2
2
votes
1 answer

Different catch2 checks on different inputs

I'm trying to test some code that requires a little bit of setup to use, and I'd like to avoid repeating the setup steps. The setup steps have some dependency on the input, but the results could be significantly different depending on what exactly…
David Maze
  • 130,717
  • 29
  • 175
  • 215
2
votes
1 answer

Catch2 compile error (no such file or directory)

I've already used Catch2 for testing sucessfully, but this time a problem occurred. I am pushing Catch2 submodule to me project (this is not a -v2.x branch) and include "../Catch2/src/catch2/catch_all.hpp" to my test files. The problem is that in…
2
votes
0 answers

catch2: how to execute another process as part of test case?

i'm trying to implement a test case in catch2 that tests usage of fifo between processes. For testing it, i want to run another process that creates and writes to fifo, while my test (using catch2) will read from this fifo. Is there a way to run a…
user893269
  • 107
  • 2
  • 10
2
votes
1 answer

How to get coverage for tests with CMake and Catch2

I'm trying to print coverage with lcov on a C++ project that is using Catch2 for tests. I'm able to run my tests and get results. However, I'm unable to get any coverage. This is the error that is shown. Capturing coverage data from . Found gcov…
ges134
  • 23
  • 1
  • 6
2
votes
2 answers

Mocking External Dependency object created inside a function without dependency injection in c++

I am trying to write unit tests in C++ and am facing an issue with creating mock objects for an external dependency using Fakeit. So we have a class similar to the following: class A { int test_method() { B obj; return…
Sam
  • 21
  • 2
2
votes
3 answers

How to create a template for creating a test executable using catch2 with qt and trompeloeil?

I have a project (with main.cpp and some headers. Yes, it is a Catch2 test project as described in this blog). It compiles and runs. My problem is: This project does nothing useful unless I add some more source files (my test cases). These source…
user9400869
2
votes
1 answer

Catch2 require the exception to be equal to something

I am looking for a replacement for this piece of code, as it gets repeated all over a test segment, where I check if it returns the correct error message (from enum). try { function_that_throws(); } catch (MyErrorEnum error) { REQUIRE(error ==…
Vahagn
  • 75
  • 8
2
votes
1 answer

Do not combine generators in Catch2 test case

I would like to use to more than one generator in a Catch2 test case. My problem is, that when there are more than two generators, they are "combined". So if I write something like this: TEST_CASE("Test legal moves on empty 2x1 board") { Board…
Melon
  • 604
  • 1
  • 7
  • 30
1 2
3
10 11