├── .gitignore ├── mdsnippets.json ├── README.md ├── HowTos ├── Set_up_Code_Coverage_on_macOS.md └── Set_up_Code_Coverage_on_Windows.md ├── Cpp_Testing_Techniques_Tips_and_Tricks.md ├── How_to_use_Approval_Tests_for_C++_Effectively.md ├── Refactoring_Superpowers.md ├── Workshop_Testing_Legacy_Code_Effectively_with_Approval_Tests.md ├── Quickly_and_Effectively_Testing_Legacy_C++_Code_with_Approval_Tests.md └── Quickly_Testing_Qt_Desktop_Applications.md /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | -------------------------------------------------------------------------------- /mdsnippets.json: -------------------------------------------------------------------------------- 1 | { 2 | "ReadOnly": false, 3 | "TocLevel": 5, 4 | "ExcludeDirectories": [ 5 | "cmake-build" 6 | ], 7 | "UrlsAsSnippets": [], 8 | "WriteHeader": false, 9 | "Convention": "InPlaceOverwrite" 10 | } 11 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # Resources and references for my talks 4 | 5 | * ["C++ Testing Techniques Tips and Tricks"](Cpp_Testing_Techniques_Tips_and_Tricks.md#top) 6 | * ["How to use Approval Tests for C++ Effectively"](How_to_use_Approval_Tests_for_C++_Effectively.md#top) 7 | * ["Quickly and Effectively Testing Legacy C++ Code with Approval Tests"](Quickly_and_Effectively_Testing_Legacy_C++_Code_with_Approval_Tests.md#top) 8 | * ["Quickly Testing Qt Desktop Applications"](Quickly_Testing_Qt_Desktop_Applications.md#top) 9 | * ["Refactoring Superpowers: make your IDE do your work, faster and more safely"](Refactoring_Superpowers.md#top) 10 | 11 | ## Workshops 12 | 13 | * [Workshop: Testing Legacy Code Effectively with Approval Tests](Workshop_Testing_Legacy_Code_Effectively_with_Approval_Tests.md#top) 14 | 15 | ## Detailed snippets and instructions 16 | 17 | This section is for small topics that I want to shared instructions or other details for, which would take up too much space in slides, or might become outdated and change over time. 18 | 19 | * Setting up code coverage measurements 20 | * [Set up Code Coverage on macOS](HowTos/Set_up_Code_Coverage_on_macOS.md) 21 | * [Set up Code Coverage on Windows](HowTos/Set_up_Code_Coverage_on_Windows.md) 22 | 23 | See also my [list of past and future presentations](https://claremacrae.co.uk/conferences/presentations.html). 24 | -------------------------------------------------------------------------------- /HowTos/Set_up_Code_Coverage_on_macOS.md: -------------------------------------------------------------------------------- 1 | # Set up C++ Code Coverage on macOS 2 | 3 | 4 | ## Contents 5 | 6 | * [Line coverage with CMake in CLion](#line-coverage-with-cmake-in-clion) 7 | * [Branch coverage with CMake](#branch-coverage-with-cmake) 8 | 9 | ## Line coverage with CMake in CLion 10 | 11 | I got this setup working on macOS: 12 | 13 | * install: 14 | * g++-8 15 | * lcov 16 | * Use [`CodeCoverage.cmake`](https://github.com/bilke/cmake-modules/blob/master/CodeCoverage.cmake) from [github.com/bilke/cmake-modules](https://github.com/bilke/cmake-modules) to adjust compiler arguments 17 | 18 | Here is how to use `CodeCoverage.cmake` to set up to use CLion's "Run with Coverage" button: add these lines in your top-level CMakeLists.txt file, before you add set any targets or add any sub-directories: 19 | 20 | ```cmake 21 | # Provide path for scripts 22 | list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/CMake") 23 | 24 | project(...) 25 | 26 | # If building the code with clang gives 'Error: could not load cache' 27 | # 1 turn COLLECT_CODE_COVERAGE to FALSE 28 | # 2 build and run the tests 29 | # 3 turn COLLECT_CODE_COVERAGE back to TRUE 30 | set(COLLECT_CODE_COVERAGE TRUE) 31 | if (COLLECT_CODE_COVERAGE) 32 | include(CodeCoverage) 33 | append_coverage_compiler_flags() 34 | set(COVERAGE_EXCLUDES 35 | "/Applications/Xcode.app/*" 36 | "/opt/local/*" 37 | "third_party/*" 38 | ) 39 | endif () 40 | ``` 41 | 42 | ## Branch coverage with CMake 43 | 44 | As of June 2020, CLion only supports line-coverage and not branch coverage. So any measuring of branch coverage needs to be done by some other mechanism. 45 | 46 | `CodeCoverage.cmake` provides a way to do this. 47 | 48 | * Add these lines to you `~/.lcovrc` 49 | ``` 50 | genhtml_branch_coverage = 1 51 | lcov_branch_coverage = 1 52 | lcov_excl_br_line = LCOV_EXCL_BR_LINE|CHECK|REQUIRE 53 | ``` 54 | * Edit the CMake for your exe to add something like this: 55 | 56 | ```cmake 57 | set(EXE_NAME GildedRose) 58 | 59 | # Set up your executable in the normal way 60 | add_executable(${EXE_NAME} 61 | main.cpp 62 | ... 63 | ) 64 | 65 | # If code coverage is enabled, add a new target, called GildedRose_branch_coverage. 66 | # Building this target will run the tests, collect coverage stats, and generate 67 | # an HTML report with branch coverage (if you have correctly adjusted your 68 | # ~/.lcovrc file) 69 | if (COLLECT_CODE_COVERAGE) 70 | set(COVERAGE_TARGET ${EXE_NAME}_branch_coverage) 71 | setup_target_for_coverage_lcov( 72 | NAME ${COVERAGE_TARGET} 73 | EXECUTABLE ${EXE_NAME} 74 | DEPENDENCIES ${EXE_NAME}) 75 | endif () 76 | ``` 77 | 78 | For more details, see the comments in [`CodeCoverage.cmake`](https://github.com/bilke/cmake-modules/blob/master/CodeCoverage.cmake). 79 | 80 | Once this is set up, you can choose the "..._branch_coverage" target in CLion and then build it. This will generate a set of HTML reports, and print out a partial path to the output files, which you then have to navigate to, to open the output. 81 | 82 | -------------------------------------------------------------------------------- /Cpp_Testing_Techniques_Tips_and_Tricks.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # C++ Testing Techniques Tips and Tricks 4 | 5 | * [Approval Tests](https://approvaltests.com) 6 | * [ApprovalTests.cpp](https://github.com/approvals/ApprovalTests.cpp) 7 | * [ApprovalTests.cpp.StarterProject](https://github.com/approvals/ApprovalTests.cpp.StarterProject) 8 | * [ApprovalTests.cpp.Qt](https://github.com/approvals/ApprovalTests.cpp.Qt) 9 | * [ApprovalTests.cpp.Qt.StarterProject](https://github.com/approvals/ApprovalTests.cpp.Qt.StarterProject) 10 | * [CppCon talk: Quickly Testing Legacy C++ Code with Approval Tests](https://www.youtube.com/watch?v=3GZHvcdq32s) 11 | * Books 12 | * [The Art of Unit Testing: With Examples in .NET](https://www.manning.com/books/the-art-of-unit-testing) 13 | * [The Art of Unit Testing, Second Edition with examples in C#](https://www.manning.com/books/the-art-of-unit-testing-second-edition) 14 | * [The Art of Unit Testing, Third Edition with JavaScript examples](https://www.manning.com/books/the-art-of-unit-testing-third-edition) 15 | * [CodeCoverage.cmake](https://github.com/bilke/cmake-modules/blob/master/CodeCoverage.cmake) 16 | * [Coverage-directed fuzzing: "Testing Legacy Code - Fuzzing for Better Input Data" - by Tina Ulbrich and Niel Waldren](https://meetingcpp.com/mcpp/slides/2019/Testing%20Legacy%20Code%20-%20Fuzzing%20for%20Better%20Input%20Data.pdf) 17 | * Code Katas - practice exercises 18 | * [Cyber Dojo](https://cyber-dojo.org) 19 | * [Emily Bache's GildedRose Refactoring Kata](https://github.com/emilybache/GildedRose-Refactoring-Kata) 20 | * [Emily Bache's Katas](https://github.com/emilybache?utf8=✓&tab=repositories&q=kata) 21 | * Emily Bache's "Advanced Testing & Refactoring Techniques" series: 22 | * [Part 1: Introducing the Gilded Rose kata and writing test cases using Approval Tests](https://www.praqma.com/stories/advanced-testing-refactoring-techniques/) 23 | * [Part 2: Refactoring item logic using ‘lift up conditional’](https://www.praqma.com/stories/advanced-testing-refactoring-techniques-2/) 24 | * [Part 3: Replace Conditional with Polymorphism](https://www.praqma.com/stories/advanced-testing-refactoring-techniques-3/) 25 | * Fuzzing 26 | * [American fuzzy lop](http://lcamtuf.coredump.cx/afl/) 27 | * [libFuzzer](https://www.llvm.org/docs/LibFuzzer.html) 28 | * [#include ](https://www.includecpp.org) 29 | * [Kevlin Henney's FizzBuzz Trek HD](https://www.youtube.com/watch?v=LueeMTTDePg) - Property Based Testing 30 | * Qt Applications 31 | * [My references for "Quickly Testing Qt Desktop Applications"](Quickly_Testing_Qt_Desktop_Applications.md#top) 32 | * [Slides for that talk](https://www.slideshare.net/ClareMacrae/quickly-testing-qt-desktop-applications) 33 | * [RapidCheck - C++ Property Based Testing](https://github.com/emil-e/rapidcheck) 34 | * Test Frameworks for C++ 35 | * [Catch2 test framework](https://github.com/catchorg/Catch2) 36 | * [doctest](https://github.com/onqtam/doctest) 37 | * [Googletest - Google Testing and Mocking Framework](https://github.com/google/googletest) 38 | 39 | 40 | ### Clare Macrae 41 | 42 | I am a consultant and trainer, helping teams test and refactor hard-to-maintain code. 43 | 44 | * [Website](https://claremacrae.co.uk) 45 | * [Blog](https://claremacrae.co.uk/blog/) 46 | * [Presentations](https://claremacrae.co.uk/conferences/presentations.html) 47 | * [Hire Me](https://claremacrae.co.uk/consulting/hire_me.html) 48 | -------------------------------------------------------------------------------- /How_to_use_Approval_Tests_for_C++_Effectively.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # How to use Approval Tests for C++ Effectively 4 | 5 | 6 | ## Contents 7 | 8 | * [Demo Code](#demo-code) 9 | * [Links](#links) 10 | * [Clare Macrae](#clare-macrae) 11 | 12 | ## Demo Code 13 | 14 | * This talk is mostly demo-based 15 | * The demo code is at: 16 | * [github.com/claremacrae/approvals_live_demo](https://github.com/claremacrae/approvals_live_demo/) 17 | * As I give this talk, I tag the versions presented, as the demos and ApprovalTests.cpp library will evolve over time: 18 | * [Tag: 2020-06-CppEurope](https://github.com/claremacrae/approvals_live_demo/tree/2020-06-CppEurope/): CppEurope #4, 23 June 2020 19 | 20 | ## Links 21 | 22 | * [Approval Tests](https://approvaltests.com) 23 | * [ApprovalTests.cpp](https://github.com/approvals/ApprovalTests.cpp) 24 | * [ApprovalTests.cpp.StarterProject](https://github.com/approvals/ApprovalTests.cpp.StarterProject) 25 | * [ApprovalTests.cpp.Qt](https://github.com/approvals/ApprovalTests.cpp.Qt) 26 | * [ApprovalTests.cpp.Qt.StarterProject](https://github.com/approvals/ApprovalTests.cpp.Qt.StarterProject) 27 | * ApprovalTests.cpp User Guide 28 | * [User Guide on Read the Docs](https://approvaltestscpp.readthedocs.io/en/latest/) 29 | * [User Guide on GitHub](https://github.com/approvals/ApprovalTests.cpp/blob/master/doc/README.md#top) 30 | * User Guide pages mentioned 31 | * [String Conversions](https://github.com/approvals/ApprovalTests.cpp/blob/master/doc/ToString.md) 32 | * [How to Use the Fmt Library To Print Objects](https://github.com/approvals/ApprovalTests.cpp/blob/master/doc/how_tos/UseTheFmtLibraryToPrintObjects.md) 33 | * [Tips for Designing Strings](https://github.com/approvals/ApprovalTests.cpp/blob/master/doc/explanations/TipsForDesigningStrings.md#top) 34 | * [Multiple output files per test](https://github.com/approvals/ApprovalTests.cpp/blob/master/doc/MultipleOutputFilesPerTest.md) 35 | * [Clare Macrae's "Quickly Testing Legacy Code" talk at C++ on Sea 2019](https://www.youtube.com/watch?v=dtm8V3TIB6k) 36 | * Code Coverage 37 | * [Set up Code Coverage on macOS](HowTos/Set_up_Code_Coverage_on_macOS.md) 38 | * [Set up Code Coverage on Windows](HowTos/Set_up_Code_Coverage_on_Windows.md) 39 | * Gilded Rose Kata 40 | * [Emily Bache's GildedRose Refactoring Kata](https://github.com/emilybache/GildedRose-Refactoring-Kata) 41 | * Emily Bache's "Advanced Testing & Refactoring Techniques" series: 42 | * [Part 1: Introducing the Gilded Rose kata and writing test cases using Approval Tests](https://www.praqma.com/stories/advanced-testing-refactoring-techniques/) 43 | * [Part 2: Refactoring item logic using ‘lift up conditional’](https://www.praqma.com/stories/advanced-testing-refactoring-techniques-2/) 44 | * [Part 3: Replace Conditional with Polymorphism](https://www.praqma.com/stories/advanced-testing-refactoring-techniques-3/) 45 | * [Angie Jones' "Verifying Entire API Responeses"](https://angiejones.tech/verifying-entire-api-responses/) 46 | * [Llewellyn Falco and Woody Zuill's "Practical Refactoring: 2 Minutes to Better Code"](https://youtu.be/aWiwDdx_rdo) 47 | 48 | ## Clare Macrae 49 | 50 | I am a consultant and trainer. 51 | 52 | * [Website](https://claremacrae.co.uk) 53 | * [Blog](https://claremacrae.co.uk/blog/) 54 | * [Presentations](https://claremacrae.co.uk/conferences/presentations.html) 55 | * [Hire Me](https://claremacrae.co.uk/consulting/hire_me.html) 56 | -------------------------------------------------------------------------------- /Refactoring_Superpowers.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # Refactoring Superpowers 4 | 5 | _Make your IDE do your work, faster and more safely_ 6 | 7 | 8 | ## Contents 9 | 10 | * [Sudoku Kata](#sudoku-kata) 11 | * [C# Version](#c-version) 12 | * [C++ Version](#c-version) 13 | * [Testing](#testing) 14 | * [Approval Tests](#approval-tests) 15 | * [Refactoring](#refactoring) 16 | * [Books and Resources](#books-and-resources) 17 | * [Videos](#videos) 18 | * [Clare Macrae](#clare-macrae) 19 | 20 | ## Sudoku Kata 21 | 22 | ### C# Version 23 | 24 | * [zoran-horvat/sudoku-kata](https://github.com/zoran-horvat/sudoku-kata) 25 | * [claremacrae/sudoku-kata](https://github.com/claremacrae/sudoku-kata) 26 | * [add-tests](https://github.com/claremacrae/sudoku-kata/tree/add-tests) branch 27 | * with Approval Tests added 28 | * [simpler-tests](https://github.com/claremacrae/sudoku-kata/tree/simpler-tests) branch 29 | * with simpler test code, and shorter history 30 | * [demo-1](https://github.com/claremacrae/sudoku-kata/tree/demo-1) branch 31 | * with "Solve puzzle from the internet" feature added 32 | 33 | ### C++ Version 34 | 35 | * [claremacrae/sudoku-kata-cpp](https://github.com/claremacrae/sudoku-kata-cpp) 36 | * [with-tests](https://github.com/claremacrae/sudoku-kata-cpp/tree/with-tests) branch 37 | * with Approval Tests added 38 | 39 | ## Testing 40 | 41 | ### Approval Tests 42 | 43 | * [Approval Tests](https://approvaltests.com) 44 | * C# and .Net 45 | * [ApprovalTests.Net](https://github.com/approvals/ApprovalTests.Net) 46 | * [ApprovalTests.Net.StarterProject](https://github.com/approvals/ApprovalTests.Net.StarterProject) 47 | * C++ 48 | * [ApprovalTests.cpp](https://github.com/approvals/ApprovalTests.cpp) 49 | * [ApprovalTests.cpp.StarterProject](https://github.com/approvals/ApprovalTests.cpp.StarterProject) 50 | * My talks on Approval Tests 51 | * ["Quickly Testing Legacy Code" talk](https://www.youtube.com/watch?v=dtm8V3TIB6k) at C++ on Sea 2019 52 | * All [past talks on Approval Tests](https://claremacrae.co.uk/conferences/presentations_by_topic.html#testing-legacy-c-code-with-approval-tests) 53 | 54 | ## Refactoring 55 | 56 | ### Books and Resources 57 | 58 | * Book: Martin Fowler's [Refactoring: Improving the Design of Existing Code](https://martinfowler.com/books/refactoring.html) 59 | * [Refactoring.com](https://refactoring.com) 60 | * [Online catalog of refactorings](https://refactoring.com/catalog/) 61 | * [Provable Refactorings](https://github.com/digdeeproots/provable-refactorings): 62 | * A collection of refactoring recipes that are provably safe. Each recipe is language-specific and rests on the rules of that language. Within that language, each will either terminate with a clear failure or will complete in a way that guarantees no change in behavior. 63 | 64 | ### Videos 65 | 66 | * Dave Farley's "Refactoring Legacy Code: STEP BY STEP" 67 | * [Part 1](https://youtu.be/p-oWHEfXEVs): Steps 1 and 2: Approval Testing and De-cluttering 68 | * [Part 2](https://youtu.be/NCjwUptCaLU): Steps 3 and 4: "Reducing Complexity" and "Composing Methods". 69 | * [Part 3](https://youtu.be/3iirETgRaRc): Refactoring Legacy Code to be Testable 70 | * Llewellyn Falco and Woody Zuill's ["Practical Refactoring: 2 Minutes to Better Code"](https://youtu.be/aWiwDdx_rdo) 71 | 72 | ## Clare Macrae 73 | 74 | I am a consultant and trainer. 75 | 76 | * [Website](https://claremacrae.co.uk) 77 | * [Blog](https://claremacrae.co.uk/blog/) 78 | * [Presentations](https://claremacrae.co.uk/conferences/presentations.html) 79 | * [Hire Me](https://claremacrae.co.uk/consulting/hire_me.html) 80 | -------------------------------------------------------------------------------- /Workshop_Testing_Legacy_Code_Effectively_with_Approval_Tests.md: -------------------------------------------------------------------------------- 1 | # Workshop: Testing Legacy Code Effectively with Approval Tests 2 | 3 | 4 | ## Contents 5 | 6 | * [Course Materials](#course-materials) 7 | * [Approval Tests](#approval-tests) 8 | * [Techniques](#techniques) 9 | * [Links](#links) 10 | * [Trainers](#trainers) 11 | * [Clare Macrae](#clare-macrae) 12 | * [Llewellyn Falco](#llewellyn-falco) 13 | 14 | 15 | 16 | ## Course Materials 17 | 18 | * [Resources](https://github.com/claremacrae/talks/blob/main/Workshop_Testing_Legacy_Code_Effectively_with_Approval_Tests.md#top) (this file) 19 | * [Slides](https://github.com/LearnWithLlew/TestingLegacyCodeCourse.slides) 20 | * [Code](https://github.com/LearnWithLlew/TestingLegacyCodeCourse.cpp) 21 | 22 | ## Approval Tests 23 | 24 | * [Approval Tests](https://approvaltests.com) 25 | * [ApprovalTests.cpp](https://github.com/approvals/ApprovalTests.cpp) 26 | * [ApprovalTests.cpp.StarterProject](https://github.com/approvals/ApprovalTests.cpp.StarterProject) 27 | * ApprovalTests.cpp User Guide 28 | * [User Guide on Read the Docs](https://approvaltestscpp.readthedocs.io/en/latest/) 29 | * [User Guide on GitHub](https://github.com/approvals/ApprovalTests.cpp/blob/master/doc/README.md#top) 30 | 31 | ## Techniques 32 | 33 | * Peel and Slice 34 | * [Using ApprovalTests in .Net: Playlist](https://www.youtube.com/user/isidoreus) 35 | * [Using ApprovalTests in .Net 12 The Peel](https://www.youtube.com/watch?v=p0tILwRZH5Q) 36 | * [Using ApprovalTests in .Net 13 Mocks](https://www.youtube.com/watch?v=PY5msaYNPrI) 37 | * [Using ApprovalTests in .Net 14 Peel & Slice](https://www.youtube.com/watch?v=sXqRWXWiXYo) 38 | * Getting code you can't build under test 39 | * See James Grenning's [Crash to Pass Toolkit](https://github.com/jwgrenning/gen-xfakes) 40 | * James' article [TDD How-to: Get your Legacy C Into a Test Harness](https://wingman-sw.com/articles/tdd-legacy-c) also describes many patterns for getting legacy C code in to a test harness 41 | * Commonly-asked questions about approval tests 42 | * [Testing exception messages](https://approvaltestscpp.readthedocs.io/en/latest/generated_docs/TestingExceptions.html) 43 | * [Controlling where Approval Tests puts the approved and received files](https://approvaltestscpp.readthedocs.io/en/latest/generated_docs/Configuration.html#using-sub-directories-for-approved-files) 44 | * Emily Bache's [Approval Tools](https://github.com/emilybache/ApprovalTools) - some scripts for bulk-reviewing and approving Approval Tests failures 45 | * Code Coverage 46 | * [Set up Code Coverage on macOS](HowTos/Set_up_Code_Coverage_on_macOS.md) 47 | * [Set up Code Coverage on Windows](HowTos/Set_up_Code_Coverage_on_Windows.md) 48 | 49 | ## Links 50 | 51 | * How Approval Tests finds diff tools 52 | * [Supported diff tools](https://github.com/approvals/ApprovalTests.cpp/blob/master/doc/Reporters.md#supported-diff-tools) 53 | * [Locations that it searches for diff tools](https://github.com/approvals/ApprovalTests.cpp/blob/master/ApprovalTests/reporters/DiffPrograms.cpp): Note that they need to be installed in standard locations 54 | * [Clare's C++ on Sea graphics-differencing talk](https://www.youtube.com/watch?v=dtm8V3TIB6k) 55 | * [Regular Expressions 101](https://regex101.com/) 56 | 57 | ## Trainers 58 | 59 | ### Clare Macrae 60 | 61 | * [Website](https://claremacrae.co.uk) 62 | * [Blog](https://claremacrae.co.uk/blog/) 63 | * [Presentations](https://claremacrae.co.uk/conferences/presentations.html) 64 | * [Hire Me](https://claremacrae.co.uk/consulting/hire_me.html) 65 | 66 | ### Llewellyn Falco 67 | 68 | * [Blog](http://llewellynfalco.blogspot.com/) 69 | * [ApprovalTests](https://github.com/approvals/) 70 | * [YouTube](https://www.youtube.com/user/isidoreus/videos) 71 | 72 | -------------------------------------------------------------------------------- /Quickly_and_Effectively_Testing_Legacy_C++_Code_with_Approval_Tests.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # Quickly and Effectively Testing Legacy C++ Code with Approval Tests 4 | 5 | 6 | ## Contents 7 | 8 | * [Demo Code](#demo-code) 9 | * [Next Training Session](#next-training-session) 10 | * [Links](#links) 11 | * [Clare Macrae](#clare-macrae) 12 | 13 | ## Demo Code 14 | 15 | * This talk is mostly demo-based 16 | * The demo code is at: 17 | * [github.com/claremacrae/approvals_live_demo](https://github.com/claremacrae/approvals_live_demo/) 18 | * As I give this talk, I tag the versions presented, as the demos and ApprovalTests.cpp library will evolve over time: 19 | * [Tag: 2020-06-CppEurope](https://github.com/claremacrae/approvals_live_demo/tree/2020-06-CppEurope/): CppEurope #4, 23 June 2020 20 | * [Branch: 2020-07-cpp-on-sea-branch](https://github.com/claremacrae/approvals_live_demo/tree/2020-07-cpp-on-sea-branch): C++ on Sea, 15 July 2020 21 | * contains the [changes I made during the demo](https://github.com/claremacrae/approvals_live_demo/compare/2020-07-cpp-on-sea-start-point...2020-07-cpp-on-sea-end-point) 22 | * [Branch: 2020-08-mucpp-branch](https://github.com/claremacrae/approvals_live_demo/tree/2020-08-mucpp-branch) MUC++, 6 August 2020 23 | 24 | ## Next Training Session 25 | 26 | * [September 2020](https://claremacrae.co.uk/blog/2020/07/approvaltests-training-course) 27 | 28 | ## Links 29 | 30 | * [Approval Tests](https://approvaltests.com) 31 | * [ApprovalTests.cpp](https://github.com/approvals/ApprovalTests.cpp) 32 | * [ApprovalTests.cpp.StarterProject](https://github.com/approvals/ApprovalTests.cpp.StarterProject) 33 | * [ApprovalTests.cpp.Qt](https://github.com/approvals/ApprovalTests.cpp.Qt) 34 | * [ApprovalTests.cpp.Qt.StarterProject](https://github.com/approvals/ApprovalTests.cpp.Qt.StarterProject) 35 | * ApprovalTests.cpp User Guide 36 | * [User Guide on Read the Docs](https://approvaltestscpp.readthedocs.io/en/latest/) 37 | * [User Guide on GitHub](https://github.com/approvals/ApprovalTests.cpp/blob/master/doc/README.md#top) 38 | * User Guide pages mentioned 39 | * [String Conversions](https://github.com/approvals/ApprovalTests.cpp/blob/master/doc/ToString.md) 40 | * [How to Use the Fmt Library To Print Objects](https://github.com/approvals/ApprovalTests.cpp/blob/master/doc/how_tos/UseTheFmtLibraryToPrintObjects.md) 41 | * [Tips for Designing Strings](https://github.com/approvals/ApprovalTests.cpp/blob/master/doc/explanations/TipsForDesigningStrings.md#top) 42 | * [Multiple output files per test](https://github.com/approvals/ApprovalTests.cpp/blob/master/doc/MultipleOutputFilesPerTest.md) 43 | * [Clare Macrae's other talks](https://claremacrae.co.uk/conferences/presentations.html) 44 | * Code Coverage 45 | * [Set up Code Coverage on macOS](HowTos/Set_up_Code_Coverage_on_macOS.md) 46 | * [Set up Code Coverage on Windows](HowTos/Set_up_Code_Coverage_on_Windows.md) 47 | * Gilded Rose Kata 48 | * [Emily Bache's GildedRose Refactoring Kata](https://github.com/emilybache/GildedRose-Refactoring-Kata) 49 | * Emily Bache's "Advanced Testing & Refactoring Techniques" series: 50 | * [Part 1: Introducing the Gilded Rose kata and writing test cases using Approval Tests](https://www.praqma.com/stories/advanced-testing-refactoring-techniques/) 51 | * [Part 2: Refactoring item logic using ‘lift up conditional’](https://www.praqma.com/stories/advanced-testing-refactoring-techniques-2/) 52 | * [Part 3: Replace Conditional with Polymorphism](https://www.praqma.com/stories/advanced-testing-refactoring-techniques-3/) 53 | * [Simon Cropp's "EmptyFiles project"](https://github.com/SimonCropp/EmptyFiles) 54 | * [Angie Jones' "Verifying Entire API Responeses"](https://angiejones.tech/verifying-entire-api-responses/) 55 | * [Llewellyn Falco and Woody Zuill's "Practical Refactoring: 2 Minutes to Better Code"](https://youtu.be/aWiwDdx_rdo) 56 | 57 | ## Clare Macrae 58 | 59 | I am a consultant and trainer. 60 | 61 | * [Website](https://claremacrae.co.uk) 62 | * [Blog](https://claremacrae.co.uk/blog/) 63 | * [Presentations](https://claremacrae.co.uk/conferences/presentations.html) 64 | * [Hire Me](https://claremacrae.co.uk/consulting/hire_me.html) 65 | -------------------------------------------------------------------------------- /Quickly_Testing_Qt_Desktop_Applications.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # Quickly Testing Qt Desktop Applications 4 | 5 | 6 | ## Contents 7 | 8 | * [Demo Code](#demo-code) 9 | * [Links](#links) 10 | * [Clare Macrae](#clare-macrae) 11 | * [Appendix](#appendix) 12 | * [Qt Test Info](#qt-test-info) 13 | * [Qt Test executables](#qt-test-executables) 14 | 15 | ## Demo Code 16 | 17 | * This talk is partly demo-based 18 | * The demo code is at: 19 | * [github.com/claremacrae/approvals_live_demo](https://github.com/claremacrae/approvals_live_demo/) 20 | * As I give this talk, I tag the versions presented, as the demos and ApprovalTests.cpp library will evolve over time: 21 | * [Tag: 2020-09-cppcon](https://github.com/claremacrae/approvals_live_demo/tree/2020-09-cppcon/): CppCon 2020, 16 September 2020 22 | 23 | ## Links 24 | 25 | * [Approval Tests](https://approvaltests.com) 26 | * [ApprovalTests.cpp](https://github.com/approvals/ApprovalTests.cpp) 27 | * [ApprovalTests.cpp.StarterProject](https://github.com/approvals/ApprovalTests.cpp.StarterProject) 28 | * [ApprovalTests.cpp.Qt](https://github.com/approvals/ApprovalTests.cpp.Qt) 29 | * [ApprovalTests.cpp.Qt.StarterProject](https://github.com/approvals/ApprovalTests.cpp.Qt.StarterProject) 30 | * [Arne Mertz's "Hello CMake" series](https://arne-mertz.de/2018/05/hello-cmake/) 31 | * [Catch2 test framework](https://github.com/catchorg/Catch2) 32 | * [FrogLogic's "Unit tests for Qt-based applications with Catch"](https://www.froglogic.com/blog/tip-of-the-week/unit-tests-for-qt-based-applications-with-catch/) 33 | * [Testing Qt Code with Catch](https://dzone.com/articles/unit-tests-for-qt-based-applications-with-catch) 34 | * [Catch2 test command-line arguments](https://github.com/catchorg/Catch2/blob/master/docs/command-line.md) 35 | * [clazy - Qt related compiler warnings and fixits](https://github.com/KDE/clazy) 36 | * [old-style-connect](https://github.com/KDE/clazy/blob/master/docs/checks/README-old-style-connect.md) - but do read the caveats. 37 | * [Clare Macrae's "Quickly Testing Legacy Code" talk at C++ on Sea 2019](https://www.youtube.com/watch?v=dtm8V3TIB6k) 38 | * [Googletest - Google Testing and Mocking Framework](https://github.com/google/googletest) 39 | * [ICS's slides on "Qt Test-Driven Development Using Google Test and Google Mock"](https://www.slideshare.net/ICSinc/webinar-qt-testdriven-development-using-google-test-and-google-mock) 40 | * [KDAB GammaRay](https://www.kdab.com/development-resources/qt-tools/gammaray/) 41 | * [Llewellyn Falco and Woody Zuill's "Practical Refactoring: 2 Minutes to Better Code"](https://youtu.be/aWiwDdx_rdo) 42 | * [Qt](https://www.qt.io) 43 | * [Qt Test framework](https://doc.qt.io/qt-5/qttest-index.html) 44 | * [Qt's "Writing Unit Tests"](https://wiki.qt.io/Writing_Unit_Tests) - now in transit to new location: [Qt Test Best Practices](https://doc-snapshots.qt.io/qt5-5.13/qttest-best-practices-qdoc.html) 45 | * [Qt's "Writing good tests"](https://wiki.qt.io/Writing_good_tests) 46 | * [ICS's slides on "QtTest Unit Testing Framework"](https://www.slideshare.net/ICSinc/qt-test-framework) - with a link to the video of the talk 47 | * [QApplication command-line arguments](https://doc.qt.io/qt-5/qguiapplication.html#QGuiApplication) 48 | * [Supported platform names](https://doc.qt.io/qt-5/qguiapplication.html#platformName-prop) - for example, run your tests with `-platform offscreen` to avoid Widgets flashing up 49 | * [Squish GUI Test Automation Tool](https://www.froglogic.com/squish/) 50 | * [Frerich Raabe's "Behavior-Driven GUI Test Automation of Qt Applications"](https://youtu.be/Oo58E6-V9c4) 51 | * [SuperCollider audio platform](https://supercollider.github.io) 52 | * [Test Pyramid](https://martinfowler.com/bliki/TestPyramid.html) 53 | * [Travis CI's "GUI and Headless Browser Testing"](https://docs.travis-ci.com/user/gui-and-headless-browsers/) 54 | * [Xvfb](https://www.x.org/releases/X11R7.6/doc/man/man1/Xvfb.1.xhtml) - virtual framebuffer X server for X11 55 | * [Xvfb on Wikipedia](https://en.wikipedia.org/wiki/Xvfb) 56 | 57 | ## Clare Macrae 58 | 59 | I am a consultant and trainer. 60 | 61 | * [Website](https://claremacrae.co.uk) 62 | * [Blog](https://claremacrae.co.uk/blog/) 63 | * [Presentations](https://claremacrae.co.uk/conferences/presentations.html) 64 | * [Hire Me](https://claremacrae.co.uk/consulting/hire_me.html) 65 | 66 | ## Appendix 67 | 68 | ### Qt Test Info 69 | 70 | * Example: [QGIS Unit Testing](https://docs.qgis.org/3.4/en/docs/developers_guide/unittesting.html) and [QGIS's test code](https://github.com/qgis/QGIS/tree/master/tests) 71 | * Generally useful pages 72 | * [Increase your QTest productivity](https://marcoarena.wordpress.com/tag/qtest-fixture/) - another auto-registering mechanism, how to create fixtures, and colour-coding test output 73 | 74 | ### Qt Test executables 75 | 76 | * Qt Tests only supports one test QObject per executable, generating large numbers of exes 77 | * Various people have tried to work around this - the following links may be useful 78 | * [Unofficial Qt Creator Blog on "Running Multiple Unit Tests" in one Qt Test program](http://qtcreator.blogspot.com/2009/10/running-multiple-unit-tests.html) 79 | * [Jaded Biologist on "Using QtTest Effectively"](https://alexhuszagh.github.io/2016/using-qttest-effectively/) 80 | -------------------------------------------------------------------------------- /HowTos/Set_up_Code_Coverage_on_Windows.md: -------------------------------------------------------------------------------- 1 | # Set up C++ Code Coverage on Windows 2 | 3 | 4 | ## Contents 5 | 6 | * [Visual Studio](#visual-studio) 7 | * [Line coverage in Visual Studio](#line-coverage-in-visual-studio) 8 | * [Branch coverage in Visual Studio](#branch-coverage-in-visual-studio) 9 | * [CLion](#clion) 10 | * [Introduction](#introduction) 11 | * [Set up clang-cl in CLion on Windows](#set-up-clang-cl-in-clion-on-windows) 12 | * [Enable exceptions for clang-cl](#enable-exceptions-for-clang-cl) 13 | * [CLion Native Coverage Tool - Line Coverage](#clion-native-coverage-tool---line-coverage) 14 | * [C/C++ Coverage Plugin - Line and Branch Coverage](#cc-coverage-plugin---line-and-branch-coverage) 15 | 16 | ## Visual Studio 17 | 18 | ### Line coverage in Visual Studio 19 | 20 | [OpenCppCoverage](https://github.com/OpenCppCoverage/OpenCppCoverage) has a Visual Studio plugin called [OpenCppCoveragePlugin](https://github.com/OpenCppCoverage/OpenCppCoveragePlugin) which can be used to collect line-coverage measurements in Visual Studio. 21 | 22 | 1. Install Visual Studio plugin called [OpenCppCoveragePlugin](https://github.com/OpenCppCoverage/OpenCppCoveragePlugin) 23 | 2. Restart Visual Studio 24 | 3. Build your program 25 | 4. Click "Run OpenCppCoverage" in Visual Studio's Tools menu 26 | 27 | ### Branch coverage in Visual Studio 28 | 29 | I have had good results with the commercial tool [BullseyeCoverage](https://www.bullseye.com). 30 | 31 | ## CLion 32 | 33 | ### Introduction 34 | 35 | I have found that code coverage in CLion on Windows works well if you have installed and are using clang-cl, downloaded from LLVM. 36 | 37 | Below I show two options to get coverage results in CLion on Windows: 38 | 39 | 1. Using CLion's native 40 | 2. Using the C/C++ Coverage Plugin 41 | 42 | I recommend the latter, but both do work. 43 | 44 | ### Set up clang-cl in CLion on Windows 45 | 46 | 1. Download the newest version of clang 47 | 1. Go to https://releases.llvm.org/download.html 48 | 2. Following the link to the GitHub release page 49 | 3. Search the download page for `-win64` 50 | 1. you will find a match something like `LLVM-12.0.0-win32.exe` 51 | 4. Download the .exe 52 | 1. for example https://github.com/llvm/llvm-project/releases/download/llvmorg-12.0.0/LLVM-12.0.0-win64.exe 53 | 2. Install the downloaded LLVM executable 54 | 1. This will install clang-cl in `C:\Program Files\LLVM\bin\clang-cl.exe` 55 | 3. Create a new CLion Toolchain to use the clang-cl you just installed 56 | 1. This is documented under [Toolchains](https://www.jetbrains.com/help/clion/2021.1/toolchains.html) 57 | 2. Go to `File | Settings | Build,Execution, Deployment | Toolchains` 58 | 3. You can duplicate an existing Visual Studio Toolchain 59 | 4. The specific settings I apply are: 60 | 1. Name: **Visual Studio clang** 61 | 2. Architecture: **x86_amd64** 62 | 3. C Compiler: **C:\Program Files\LLVM\bin\clang-cl.exe** 63 | 4. C++ Compiler: **C:\Program Files\LLVM\bin\clang-cl.exe** 64 | 4. Create a new CLion CMake Profile that uses your new Toolchain 65 | 1. This is documented under [CMake](https://www.jetbrains.com/help/clion/2021.1/cmake0.html) 66 | 2. Go to `File | Settings | Build,Execution, Deployment | CMake` 67 | 3. You can duplicate an existing Profile 68 | 4. The specific settings I apply are: 69 | 1. Name: **Debug-Visual Studio clang** 70 | 2. Build type: **Debug** 71 | 3. Toolchain: **Visual Studio clang** (that is, the Toolchain you created in the previous step) 72 | 73 | ### Enable exceptions for clang-cl 74 | 75 | If you are using Approval Tests, building with clang-cl will probably give you errors like this: 76 | 77 | ``` 78 | C:\Code\TestingLegacyCodeCourse.cpp\third_party/ApprovalTests.v.10.3.0.hpp(3022,13): 79 | error: cannot use 'throw' with exceptions disabled 80 | throw ApprovalMissingException(receivedPath, approvedPath); 81 | ^ 82 | ``` 83 | 84 | You can edit your top-level CMakeLists.txt file to add these lines, after the `project(...)` line: 85 | 86 | ```cmake 87 | if (MSVC) 88 | # Enable exceptions for clang-cl 89 | add_compile_options(/EHsc) 90 | endif () 91 | ``` 92 | 93 | ### CLion Native Coverage Tool - Line Coverage 94 | 95 | The [CLion Code Coverage Documentation](https://www.jetbrains.com/help/clion/2021.1/code-coverage-clion.html) shows how to set up code coverage in general. 96 | 97 | However the following steps may be all you need, after you have installed clang-cl in the earlier section. 98 | 99 | You should now be able to select the **Debug-Visual Studio clang** CMake Profile in CLion and use `Run | Run [program-name] with Coverage`. 100 | 101 | The first time you do this, the tests will run and CLion will likely show a pink box that says: 102 | 103 | ``` 104 | Could not find code coverage data 105 | Make sure the target application is compiled with the required compiler options. 106 | Would you like to add them automatically? 107 | Fix and rerun 108 | ``` 109 | 110 | **Click the blue "Fix and rerun" text**, and CLion will create a new CMake profile, with the name " Coverage" added. 111 | 112 | From this point on, with that Coverage profile, you will be able to `Run | Run [program-name] with Coverage`. 113 | 114 | ### C/C++ Coverage Plugin - Line and Branch Coverage 115 | 116 | There is a CLion plugin called [C/C++ Coverage](https://plugins.jetbrains.com/plugin/11031-c-c--coverage) that provides more thorough code coverage data and presentation than the built-in CLion coverage facility. 117 | 118 | Its [GitHub page](https://github.com/zero9178/C-Cpp-Coverage-for-CLion/blob/master/README.md) has some useful notes and background information. 119 | 120 | However the following steps may be all you need, after you have installed clang-cl in the earlier section. 121 | 122 | 1. Install the C/C++ Coverage Plugin 123 | 1. Go to `File | Settings | Plugins` 124 | 2. Click Marketplace 125 | 3. Search for Coverage 126 | 4. Click on **C/C++ Coverage** 127 | 5. Click Install 128 | 6. Accept the prompt to re-start CLion 129 | 130 | You should now be able to select the **Debug-Visual Studio clang** CMake Profile in CLion and use `Run | Run [program-name] with C/C++ Coverage Plugin`. 131 | 132 | 133 | The first time you do this, the tests will run and CLion will likely show a grey box that says: 134 | 135 | ``` 136 | Missing compilation flags 137 | Compiler flags for generating coverage are missing. Would 138 | you like to creae a new profile with them now? Create 139 | ``` 140 | 141 | **Click the blue "Create" text**, and the plugin will create a new CMake profile, with the name " Coverage" added. 142 | 143 | From this point on, with that Coverage profile, you will be able to `Run | Run [program-name] with C/C++ Coverage Plugin`. 144 | --------------------------------------------------------------------------------