Questions tagged [catch-unit-test]

Catch is a unit testing framework for C++

Catch2 is a unit testing framework for C++11 and later. 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.

93 questions
2
votes
1 answer

C++ Catch Framework Deal with C's assert?

I have unittests using the Phil Squared's Catch Testing framework in combination with some third party code that is using assert. During development it happens quiet often that through some bug assertions are raised and the program is aborted. In…
JE42
  • 4,881
  • 6
  • 41
  • 51
2
votes
1 answer

Catch Unit Test Ordering

I would like to use Catch to do unit testing on a C++ lib. However I need the most of the test cases to be run in an order. ie the library needs to be init in a certain way and then users logged in etc. Is there any design pattern for achieving…
2
votes
2 answers

Exceptions and BDD in C++ - Catch library

I've been using Boost.Test so far but am now looking into using BDD with Catch instead, but I have some trouble figuring out a nice way of handling exceptions. Say I've got a test like this: SCENARIO("connection handling", "[network]") { …
dutt
  • 7,909
  • 11
  • 52
  • 85
2
votes
2 answers

Catch test case order

Can I guarantee the order of execution with multiple TEST_CASEs with Catch? I am testing some code using LLVM, and they have some despicable global state that I need to explicitly initialize. Right now I have one test case that's like…
Puppy
  • 144,682
  • 38
  • 256
  • 465
1
vote
2 answers

How can I make my first test with Catch for my Qt application?

I am trying to learn/use Catch (https://github.com/catchorg/Catch2) for the first time on a Qt applcation. I am trying to follow the tutorial presented on Catch's initial page (https://github.com/catchorg/Catch2/blob/devel/docs/tutorial.md#top). The…
Rsevero
  • 157
  • 2
  • 11
1
vote
0 answers

Defining command line options in CMakeLists.txt

I have created small project for using catch2 testing framework. I set the specific command line option called --use-colour to yes in terminal like below: root@ramil-instance:~/testing/build# ./testing --use-colour yes How can I define this command…
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
1
vote
1 answer

Detect specific tag match in Catch2 at runtime

I have integration tests in my Catch2 project that depend on some expensive global state being set up. I'd like to only initialize that global state when the test runner will actually be testing the systems that depend on it. What I have appears to…
s3cur3
  • 2,749
  • 2
  • 27
  • 42
1
vote
1 answer

kill syscommand yields a failure in Catch2 test case

I'm using Catch2 for testing in C++. My test case forks a child process and at some point the parent process sends a kill(pid, SIGTERM) to it to clean it up. However, I get the following error from Catch2. FAILED: due to a fatal error condition: …
user11909399
  • 49
  • 1
  • 7
1
vote
1 answer

Is there a way with catch framework to compare stream or files?

I have seen in the boost testing tools the macro: BOOST__EQUAL_COLLECTION(left_begin, left_end, right_begin, right_end) which can work for streams by using ifstream_iterator. Does Catch framework provide such a way to compare streams/files?
FlashMcQueen
  • 635
  • 3
  • 13
1
vote
1 answer

xcode REMOVES weird control character FROM source

** Update I was trying to understand how/why XCode appears to be adding a weird character to my C++ source when in fact it was removing it. I am creating a simple class and using the CATCH2 testing framework as I work through a C++ course. I have a…
Cliff
  • 10,586
  • 7
  • 61
  • 102
1
vote
1 answer

I am getting issues, when compiling my code in codeblocks C++

I am trying to do my assignment for data structures class. The question is 1) Compile with UNIT_TEST defined and then run with -d yes to see the time it takes in seconds. Report that time in submission box along with the time you found when…
Lostttt
  • 9
  • 5
1
vote
1 answer

Redefined Catch unit tests

I'm testing a huge piece of software and would like to use Catch for this task. I'm using the "single include" version 1.9, integrating it in Visual Studio 2012 update 4 and using C++04 standard. As you will see below, I use three ".cpp" files. Each…
phagio
  • 196
  • 1
  • 14
1
vote
1 answer

Any way to get code coverage metrics from Catch C++ tests in Visual Studio 2017?

I have C++ project in VS 2017 with some Catch tests in it. But I am not able to figure out how to get the test coverage metrics. Although I prefer native VS solution I am happy to use VS extensions of necessary, but from what I can see ReSharper…
NoSenseEtAl
  • 28,205
  • 28
  • 128
  • 277