
Install Google Test across Linux, CMake, and Windows Visual Studio, and explore a sample project with a library and a test runner. Compare static and dynamic linking.
Instead of installing GTest, we will use FetchContent in CMake to get the framework for us
Create a minimal Google Test project on Linux to verify an add function using TEST and ASSERT_EQ, build with CMake or g++, and link Google Test (and pthread), enabling C++11.
Move the tested code into a common library and link it to both the test runner and the main application using CMake.
Explore the big picture of software testing, from unit testing and white-box approaches to integration and system testing, and understand functional, stress, load, and acceptance testing.
Explore the three-part unit test structure: arrange, act, and assert, including setup, execution, and verification. Emphasize single-behavior tests and avoid risky cleanup, for clearer, more maintainable code.
Explore unit testing with Google Test by building a count_positives function test suite using the TEST macro, arranging input vectors, performing actions, and asserting expected results.
Learn how fatal and non-fatal assertions control test flow in Google Test and Google Mock, using assert and expect to verify true, false, equal, not equal, and lower-than or greater-than.
Learn how to use assertions designed for C strings in Google Test, including cert_eq for equality, cert_str for content comparison (not pointers), and cert_str_case_eq for case-insensitive checks.
Learn to test exception behavior in Google Test using assert throw, assert any throw, and assert no throw to verify a function's exception type or absence of exceptions.
Use test fixtures to reuse setup and teardown when they are similar. A fixture is a class derived from the testing namespace's test class with overridable setup and teardown.
Demonstrates using a test fixture to share setup for testing an account class with deposit, withdraw, getBalance, and transfer, including setup, teardown, and fixture-based tests.
Leverage parameterized tests to run the same test body with different inputs by extending a param template class and instantiating test suite P with generators range, values, and combine.
Small update
Mastering mocking techniques to isolate tests by replacing dependencies with controllable objects, verify calls and parameters with matchers, using both old and new methods in Google Test and Google Mock.
Learn to mock methods by extending a class and using the mock method macro, covering return type, parameters, const and noexcept, plus legacy versus current versions in Google Mock.
Learn to define method behavior in Google Mock using on call and expect call, chaining actions, return values, and constraints like times and matchers to verify exact call patterns.
Demonstrates mocking with Google Test and Google Mock by validating updateSalary calls on a database connection, using EXPECT_CALL, exact invocation count, and the testing::_ matcher for flexible parameters.
Show how to configure Google Mock actions for specific mock calls, including throwing errors with WillOnce and testing::Throw, and using free functions, lambdas, bound member functions, or std::bind.
We also have a quick look at what other projects related to Google Test exist.
Configure the test project's properties and debugging command line arguments in Visual Studio to generate an xml report for Google Test.
This course is for software developers and students who want to be better programmers by writing more solid, bug-free code using the Google Test framework.
Your code will get better and you will have more confidence that your code is correct, because you will catch more bugs using automated tests.
How many times did this happen to you? You wrote new code, and after your hard work is done, you find that you broke features that used to work? And you had to waste more hours finding and fixing the bugs... This problem can get solved in most cases by using automated tests, especially unit tests.
No experience with automated testing is required. Very basic C++ knowledge is needed, nothing too sophisticated.
If you are completely new to Google Test, this course is just for you! If you already have some knowledge, look at the course content and see if you find some more advanced features that you didn't know about.
Google Test works on multiple platforms. You can use any platform you like. In this course, I am doing it on:
Windows (Visual Studio)
Linux (CMake or compiling directly from the command line)
Other platforms will be added if you suggest them to me
There are slides and hands-on coding examples in each section. I recommend that you try the examples and play around with them.
Here's a brief presentation of the course content:
Optional videos: Setting up on Windows (Visual Studio) and on Linux (CMake and GCC)
Basics of unit testing:
Unit test structure
Assertions - numeric, string, exceptions
Reusing code between tests (test fixtures, SetUp() and TearDown())
Parameterized tests: generate multiple tests by writing one single function.
Mocking - replacing real objects with fakes that you can control):
Basics
Setting the behaviour of mocks
Matchers