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

Point of REQUIRE_NOTHROW in the catch c++ testing framework

What is the point of the REQUIRE_NOTHROW assertion? If I just put a statement and don't wrap it in any assertion macro it will fail if it throws anyway?
Baruch
  • 20,590
  • 28
  • 126
  • 201
3
votes
1 answer

Catch fails on simple example

I am trying to integrate Catch unit testing to my project but it fails for the currently available Catch v1.10.0 Generated: 2017-08-26 15:16:46.676990 Example: test.cpp #include "catch.hpp" #define CATCH_CONFIG_MAIN TEST_CASE("CATCH TEST"){ …
El Dude
  • 5,328
  • 11
  • 54
  • 101
3
votes
1 answer

cmake ExternalProject_Add how to download URL non-tar file?

How does one set up an External project to download a link that isn't a .tgz file? For example Catch provides a release that is a single header distribution. I would like to just download this rather than the git repo or the .tgz release. But I…
Tal
  • 105
  • 9
3
votes
2 answers

String convertion of function expression with parameters in Catch assertion

If I run the following test witch Catch bool eq(int x, int y) { return x == y; } TEST_CASE("operator vs. function call") { int x = 1; int y = 2; CHECK(x == y); CHECK(eq(x, y)); } I get the following…
maiermic
  • 4,764
  • 6
  • 38
  • 77
3
votes
1 answer

"Catch" unit testing framework - REQUIRE_THROWS_AS

I started to use "Catch" unit testing framework and so far it's really great. I have used VS built in unit testing framwork with great pain . one thing I have noticed that the macro REQUIRE_THROWS_AS does not behave as one would expect from the…
David Haim
  • 25,446
  • 3
  • 44
  • 78
3
votes
1 answer

how to organize fixture data and access them from tests in C/C++

How do I compute the path to data fixtures files in test code, given: test/{main.cpp,one_test.cpp,two_test.cpp} compilation done in build/ test/fixtures/{conf_1.cfg} The problem I'm facing is as follows: /* in test/one_test.cpp */ TEST_CASE(…
foudfou
  • 976
  • 6
  • 11
3
votes
2 answers

Dealing with optional tests

The absence of a way to skip a test in CATCH, Google Test and other frameworks (at least in the traditional sense, where you specify the reason for doing so and see it in the output) made me think if I need it at all (I've been using UnitTest++ in…
Alec Mev
  • 4,663
  • 4
  • 30
  • 44
2
votes
1 answer

Using Gcov with CMake and Catch

I want to use Gcov to report coverage for my static library Catch test suite, compiled using CMake. . ├── CMakeLists.txt ├── bin ├── CMakeModules │   └── CodeCoverage.cmake ├── src │   ├── some_function.cpp │   ├── another_function.cpp │   └──…
Inigo Selwood
  • 822
  • 9
  • 20
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

Include file downloaded by Bazel http_file

I'm using Bazel to build my project. I'd like to use the single-header test framework, Catch v2. I decided to use the http_file rule to make Bazel download the catch header. My WORKSPACE file looks like…
erenon
  • 18,838
  • 2
  • 61
  • 93
2
votes
2 answers

Boolean concatenation cannot be compiled

I have the following simple expression in my Catch Testframework. Ideally, the test should issue a warning, if the test fails. Unfortunately, Catch is not able to compile the following code fragment: #define CATCH_CONFIG_MAIN #include…
Aleph0
  • 5,816
  • 4
  • 29
  • 80
2
votes
1 answer

Why do we need to compile a main test file separately with Catch?

I wrote the following Makefile (which does work as expected): CXX2 = clang++ CXXFLAG2 = -std=c++11 -c -g -O0 -Wall -Wextra LD2 = clang++ LDFLAG2 = -std=c++11 testing: data_test.o test_main.o dataframe.o csvreader.o course.o $(LD2) $^ $(LDFLAG2)…
rb612
  • 5,280
  • 3
  • 30
  • 68
2
votes
1 answer

What files are linked in an mbed OS 5 project?

I'm writing an external library (a component controller) for use with mbed 5 and plan to make it available in the mbed repositories. I want to write tests to confirm that my code is working properly, but they're just regular ordinary unit tests and…
chrylis -cautiouslyoptimistic-
  • 75,269
  • 21
  • 115
  • 152
2
votes
1 answer

Does C++ Catch has something like NUnit's TestCase with multiple parameter/input options

NUnit has the following feature where you can specify different values for a test with a TestCase attribute. Does Catch has something similar? [TestCase(12,3,4)] [TestCase(12,2,6)] [TestCase(12,4,3)] public void DivideTest(int n, int d, int q) { …
Mochan
  • 1,329
  • 1
  • 13
  • 27
2
votes
2 answers

How can I allow vector to be passed to INFO(), CAPTURE(), WARN(), etc. while avoiding illegally extending the std namespace?

In Catch Unit Test v1.8.1, with gcc 6.2.0, I'm trying to conveniently output the contents of a vector when a test fails by passing the vector to INFO(...) or CAPTURE(...). To do so I'm overloading the stream insertion operator: #include…
Quokka
  • 174
  • 1
  • 3
  • 10