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

Getting external dependency with cmake

I am writing a small library in c++ with no external dependencies, except for testing where I want to use catch2. So I'd rather not include the project and thought I could just download it when needed with cmake, but so far it looks like cmake only…
ZerataX
  • 43
  • 5
2
votes
0 answers

Redundant namespace declaration in signal in order to use QSignalSpy

I'm trying to utilize QTest in combination with Catch and QSignalSpy to test my applications. I have to say, that I'm using Qt 5.10.0, which might be important. Recently I stumbled across a strange behavior, that I couldn't really…
Aleph0
  • 5,816
  • 4
  • 29
  • 80
2
votes
2 answers

Catch2 forces me to add a cast to std::string to my exceptions, can this create other issues?

I'm using Catch2 to write my unit tests. One thing I want to do is make sure that I'm catching the correct exception. I throw the same exceptions in many circumstances, so just knowing that I'm catching an std::logic_error doesn't prove that a…
Alexis Wilke
  • 19,179
  • 10
  • 84
  • 156
2
votes
2 answers

Catch2 with CMake and Visual Studio

I'm trying to setup Catch2 test framework for a library I have built. I'm using CMake and Visual Studio 2017. My project structure is: executable-project/ |-- library |--include/ | |--SUT.h |--src/ | |--SUT.cpp …
kovac
  • 4,945
  • 9
  • 47
  • 90
2
votes
1 answer

catch2 single-include causes "undefined reference" in test

I have seen plenty of examples with the same issue, but they did not apply to my situation. I have the following file structure: unit-tests/CMakeLists.txt unit-tests/FlaAlgoTests/CMakeLists.txt unit-tests/FlaAlgoTests/catch_test_runner.cpp In…
Daniel Paczuski Bak
  • 3,720
  • 8
  • 32
  • 78
2
votes
1 answer

How to integrate Catch2 as external library with CMake?

I am trying to set up a learning project using Catch2 and I decided that it was best to clone the repository in a Cpp folder, so I could get updates and use it for other C++ projects. The installing method is as described here. The basic folder…
Adrian
  • 755
  • 9
  • 17
2
votes
0 answers

c++/catch2: reference code from seperate test dir

Before trying to do any unit testing, I had a directory like mything.h mything.cpp mything2.h mything2.cpp driver.cpp // contains main() Makefile Then I would make and run the produced executable; this executable was produced in the root directory…
Tommy
  • 12,588
  • 14
  • 59
  • 110
2
votes
1 answer

how to use CTest with Node js command, for testing JS file compiled from C++ using emscripten, and use Catch2?

I am try to use Catch2 library for testing and compile it with emscripten and run the test. The directory structure of my project look like this |- CMakeLists.txt |- build |   |- ... |   |- try-test.js |   |- try-test.wasm |   |- try-test.wast |-…
janucaria
  • 191
  • 2
  • 12
2
votes
1 answer

How to check the same condition in several Catch2 test cases

I have to check the some condition (eg. initial state) in several test cases. I cannot use CHECK in function and I would like to replace the current macro if possible. #include "catch.hpp" #define CHECK_INITIAL_STATE() \ CHECK(first_condition);…
Jónás Balázs
  • 781
  • 10
  • 24
1
vote
2 answers

How to make Catch2 test run after every rebuild?

I do have some experience with rust and cargo. It's really convenient cargo running test at every build by default. Is there anyway I can get similar behavior with CMake and Catch2 for C++ project? Here is my project structure, and…
lighthouse
  • 413
  • 2
  • 10
1
vote
1 answer

Catch2 found by cmake but not accepted due to version mismatch

I installed Catch2 on Windows, located in C:/Program Files (x86)/Catch2/, but something went wrong when I use find_package to use Catch2. In detail, using this cmake file: project(UnitTest) cmake_minimum_required(VERSION 3.20) set(CMAKE_CXX_STANDARD…
Gorun
  • 134
  • 6
1
vote
0 answers

how to set the same expectation for an array of mock objects in trompeloeil?

I have an array of mocked objects and I need to provide the same expectation for many of them. I can only succeed in this by manually writing the expectation for each object of the array. the function under test struct IWheel { virtual bool…
Grim Fandango
  • 2,296
  • 1
  • 19
  • 27
1
vote
1 answer

Create custom reporter for Catch2 in single header version

There is already a section in Catch2 documentation about how to create custom reporters. The problem is that this seems to work only for the non-single header version of Catch2. Using single header version of Catch2, the two base classes for…
Mickaël C. Guimarães
  • 1,020
  • 2
  • 14
  • 32
1
vote
0 answers

C++ Catch2 does not show desired output

I am new to the C++ language and I am trying to understand the Catch2 unit test framework. I followed the example given on the github page. I use visual studio code with the compiler g++ 12.2.0. I made a simple project with two…
rrnl
  • 11
  • 2
1
vote
0 answers

qDebug output in qtCreator while running unit tests with catch2

I have a project with unittests which are implemented with catch2 and using the catch2-integration in qtcreator. The unittests contain qDebug()<<"message" calls. The project uses CMAKE as build system. Everything compiles and I can both run the…
Joma
  • 2,334
  • 2
  • 20
  • 25