From the course: Introducing Functional Programming in C++

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Unit testing functional programming

Unit testing functional programming - C++ Tutorial

From the course: Introducing Functional Programming in C++

Start my 1-month free trial

Unit testing functional programming

- [Instructor] One of the nice benefits of functional programming is easier testing, not having classes to mock or instantiate makes testing simpler, using pure functions whose outputs solely depends on their inputs, means the tests almost write themselves. Let's take a quick look at unit testing a C++ program written functionally. We'll download the open source, Catch2, unit test framework. So, here's the Catch2 website, we're going to scroll down until we see the logo, and then, just past the logo, there is a long blue link, which says single header can be downloaded directly using this link. We're going to click that. That will download the catch.hpp file to our machine, and then, we're going to copy that catch.hpp file to our working directory. Yeah, we're going to go to Visual Studio Code, and here, we have main.cpp plus catch.hpp. This code uses the Catch2 unit test framework. The define statement CATCH_CONFIG_MAIN tells catch to create a main function. You only need to do this…

Contents