Back to Basics Unit Testing
Modern C++ Testing with Catch2 Catch2 https://github.com/catchorg/Catch2 Frameworks Part 0: Basics 9auto abs(int x) -> int; math.hpp math.cpp test_math.cpp #include <catch2/catch_test_macros.hpp> Frameworks Part 0: Basics 10auto abs(int x) -> int; math.hpp math.cpp test_math.cpp #include <catch2/catch_test_macros.hpp> #include "math.hpp" TEST_CASE("Absolute value tests"){ CHECK( abs( 5) Randomness seeded to: 3662634875 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ output.s is a Catch2 v3.7.0 host application. Run with -? for options ---------------------------------------------------------0 码力 | 109 页 | 4.13 MB | 5 月前3Quickly Testing Qt Desktop Applications With Approval Tests
Test Executable22 C++ Test Runners • Lots to choose from: • Catch2, with a little bit of Qt Test • Tricks needed to use Qt with Catch2 – Useful if using different framework23 Setting up testsuite GoToLineToolFixture() { mGoToLineWidget.raise(); mGoToLineWidget.show(); // ... and so on ...46 Fixtures in Catch2 • Fixtures share code between tests • Also improve test design TEST_CASE_METHOD( GoToLineToolFixture ApprovalTests.cpp.Qt59 Introducing ApprovalTests.cpp.Qt • github.com/approvals/ApprovalTests.cpp.Qt Catch2 ApprovalTests.cpp Qt5 Test Qt5 Widgets ApprovalTests.cpp.Qt60 Introducing ApprovalTests.cpp.Qt0 码力 | 77 页 | 6.96 MB | 5 月前3MACRO-FREE TESTING WITH C++20
COM/BOOST-EXT/UT HTTPS://GITHUB.COM/BOOST-EXT/UT 13 / 14CATCH2 - CATCH2 - HTTPS://GODBOLT.ORG/Z/JFB7JK HTTPS://GODBOLT.ORG/Z/JFB7JK 14 / 14CATCH2 - CATCH2 - HTTPS://GODBOLT.ORG/Z/JFB7JK HTTPS://GODBOLT.ORG/Z/JFB7JK [=]() mutable #define SECTION(name) ut::test{"section", name} = [=]() mutable 14 / 14CATCH2 - CATCH2 - HTTPS://GODBOLT.ORG/Z/JFB7JK HTTPS://GODBOLT.ORG/Z/JFB7JK #define REQUIRE(...) ut::expect(that SECTION("resize bigger") { v.resize(10); REQUIRE(10 == std::size(v)); }; }; 14 / 14CATCH2 - CATCH2 - HTTPS://GODBOLT.ORG/Z/JFB7JK HTTPS://GODBOLT.ORG/Z/JFB7JK #define REQUIRE(...) ut::expect(that0 码力 | 53 页 | 1.98 MB | 5 月前3Back To Basics Debugging and Testing
Tests run fast – tight feedback loop. But… Assumptions!UNIT TESTING FRAMEWORKS ● Google Gest ● Catch2 ● Boost.Test ● CppUTest ● doctestGOOGLE TEST (GTest) // Tests factorial of 0. TEST(FactorialTest EXPECT_EQ(Factorial(2), 2); EXPECT_EQ(Factorial(3), 6); EXPECT_EQ(Factorial(8), 40320); }Catch2 #include <catch2/catch_test_macros.hpp> TEST_CASE( "Factorials are computed", "[factorial]" ) { REQUIRE(0 码力 | 50 页 | 2.04 MB | 5 月前3Cetting Started with C++
microsoft-test-framework-for-cpp Only available with Visual Studio Catch2 https://github.com/catchorg/Catch2 Package Managers: catch2 Boost.Test https://boost.org/libs/test vcpkg: boost-test Conan:0 码力 | 95 页 | 4.71 MB | 5 月前3Back to Basics Testing
Test Google Test Catch/ Catch2CppUnit CppUnitLite Boost.Test Google Test Catch/ Catch2 doctestCatch/ Catch2 doctest UT CppUnit CppUnitLite Boost.Test Google TestJetBrains Developer Ecosystem0 码力 | 79 页 | 25.86 MB | 5 月前3Back to Basics: The structure of a Program
Precompiled files (libstdc++.a, libc++.so, msvcrt.lib, ws2_32.dll, crt1.o) • Source files (Boost, Catch2) • Resources (icons, images, translations) CppCon 2020 - The Structure of a Program 5Copyright Precompiled files (libstdc++.a, libc++.so, msvcrt.lib, ws2_32.dll, crt1.o) • Source files (Boost, Catch2) • Resources (icons, images, translations for I18N) CppCon 2020 - The Structure of a Program 60 码力 | 64 页 | 390.34 KB | 5 月前3Monadic Operations in Modern C++: A Practical Approach
8Technologies we use ● C++ 20 ● vcpkg ● Many 3rd-party libraries (e.g. ranges-v3, tl-expected, catch2 etc) ● Qt for UI on devices 9Briefly about Qt 10 C++ code: ● Business logic ● Integration0 码力 | 61 页 | 411.49 KB | 5 月前3CROSS PLATFORM PITFALLS AND HOW TO AVOID THEM
execute a complete suite of tests Cross-platform unit testing frameworks Google Test Boost.Test Catch2 Use them together!DEMO #2 Google Test, remote debugging in Visual Studio & GitHub actionsDemo0 码力 | 67 页 | 360.44 KB | 5 月前3Scientific Unit Testing
Fedor Pikus, Back to Basics: Test-driven Development CppCon 2019 Phil Nash, Modern C++ Testing with Catch2 CppCon 2018 (And see any number of other talks by Phil on the subject) Kevlin Henney: Structure0 码力 | 45 页 | 1.91 MB | 5 月前3
共 75 条
- 1
- 2
- 3
- 4
- 5
- 6
- 8