Catch2if (NOT TARGET Catch2) project(Catch2 CXX) set(CMAKE_CXX_STANDARD 11) add_library(${PROJECT_NAME} INTERFACE) target_include_directories(${PROJECT_NAME} INTERFACE ${CMAKE_C }/include) # Mimic the library names in Catch2's own CMake files: add_library(Catch2::Catch2 ALIAS Catch2) # This one is historical, left over from when ApprovalTests.cpp was first created. #0 码力 | 1 页 | 519.00 B | 1 年前3
91HeLLoApprovatstarget_link_libraries(${EXE_NAME}) shared code::shared code ApprovalTests::ApprovalTests Catch2::Catch2 ) target_compile_definitions(${EXE_NAME} PRIVATE CATCH_CONFIG_FAST_COMPILE) add_test(NAME ${EXE_NAME}0 码力 | 1 页 | 406.00 B | 1 年前3
CMakeLists.txtcppcon_add_test(no_service SOURCES async_event.cpp main.cpp pending.cpp LIBRARIES Asia::asio Catch2::Catch2 no_service)0 码力 | 1 页 | 122.00 B | 1 年前3
Gilded RosealsAllSteps.cpp ) target_link_libraries(${EXE_NAME} ApprovalTests::ApprovalTests Catch2::Catch2 ) target_compile_definitions(${EXE_NAME} PRIVATE CATCH_CONFIG_FAST_陀螺仪) add_test(NAME ${EXE_NAME}0 码力 | 1 页 | 816.00 B | 1 年前3
96QImagehelpers/QImageExamples.h ) target_link_libraries(${EXE_NAME} ApprovalTestsQt::ApprovalTestsQt Catch2::Catch2) target_compile_definitions(${EXE_NAME} PRIVATE CATCH_CONFIG_FAST_陀螺仪) add_test(NAME ${EXE_NAME}0 码力 | 1 页 | 430.00 B | 1 年前3
CMakeLists.txt"${CMAKE_CURRENT_LIST_DIR}/cmake/modules" include(cmake/cppCon20Find.cmake) find_package(Catch2) include(GNUInstallDir) if(Catch2_FOUND) enable_testing() endif() include(cmake/Functions0 码力 | 1 页 | 625.00 B | 1 年前3
Back to Basics Unit Testingsignal: SIGSEGV ## Unit Test Frameworks ## Catch2 https://github.com/catchorg/Catch2 ## Phil Nash ## Modern C++ Testing with Catch2  -> int { 2 if (x >= 0) return x; 4 } 3 else return -x; ### test_math.cpp 1 #include <catch2 catch_test_="" macros.hpp=""> 2 #include "math.hpp" 4 TEST CASE("Absolute value tests") thingcatch2> ### math.hpp auto abs(int x) -> int; ### math.cpp 1 auto abs(int x) -> int { 2 if (x >= 0) return x; 4 } 3 else return -x; ### test\_math.cpp 1 #include <catch2 catch_test_=""0 码力 | 109 页 | 4.13 MB | 1 年前3
Back To Basics Debugging and TestingTests run fast – tight feedback loop. But... Assumptions! ## UNIT TESTING FRAMEWORKS Google Gest Catch2 Boost.Test • CppUTest • doctest , 2); EXPECT_EQ(Factorial(3), 6); EXPECT_EQ(Factorial(8), 40320); } ## Catch2 #include <catch2 catch_test_macro.hpp=""> TEST_CASE("Factorials are computed", "[factorial]") REQUIRE(Factorial(2) == 2); REQUIRE(Factorial(3) == 6); REQUIRE(Factorial(10) == 3628800); }catch2> ## MOCKING / DEPENDENCY INJECTION  ut::expect(that % ___VA_ARGS_) ___VA_ARGS___} = [=]() mutable #define SECTION(name) ut::test{"section", name} = [=]() mutable ### CATCH2 - HTTPS://GODBOLT.ORG/Z/JFB7JK #define REQUIRE(...) ut::expect(that % ___VA_ARGS_) #define TEST_CASE( SECTION("resize bigger") { v.resize(10); REQUIRE(10 == std::size(v)); }; ### CATCH2 - HTTPS://GODBOLT.ORG/Z/JFB7JK #define REQUIRE(...) ut::expect(that % ___VA_ARGS_) #define TEST_CASE(0 码力 | 53 页 | 1.98 MB | 1 年前3
Quickly Testing Qt Desktop Applications With Approval Testsments/7/3/8/2/738283a87fcd3a9557cb4e1867384077/p22_3.jpg) • Catch2, with a little bit of Qt Test • Tricks needed to use Qt with Catch2 – Useful if using different framework ## Setting up testsuite mGoToLineWidget.raise(); mGoToLineWidget.show(); // ... and so on ... ## Fixtures in Catch2 • Fixtures share code between tests • Also improve test design 












