Testdriven C++ with Catch
summary
Claim: Catch is a single-header C++ test framework that compiles with one include and a single #define to generate main, uses natural expressions via require (it decomposes LHS op RHS to show values), supports nested sections for staged tests, and filters with tags like [hide] and [integration]. Demos show compilation and colored terminal, XML/JUnit reporters, a fuzzy float comparator (aox), broad platform support (mac, Visual Studio, Linux), and planned generators and matchers.
AI-written summary · about
chapters (24)
- 0:00Start
- 2:54Deliberate Error
- 5:45Code Demo
- 9:42Tdd Style
- 12:37Why Do We Need another Test Framework
- 13:29Expressiveness
- 16:46Floating Point Comparisons
- 20:39Relationship between Size and Capacity
- 22:10One Assert per Test
- 31:35Info Macro
- 42:12Operators by Precedents
- 47:27First Item Generators Has Been Something I'Ve Been Working On for a While this Is a Way of Doing Parameterised Tests Maybe Even Property Based Testing Especially Quite a an Exciting Area but Something That I Really Want To Get Right so We Need the Time To Dispenser Work on It but I'Ve Got a New Implementation of It I'M Sure after I'Ve Finished this Talk I'M Going To Get Back to Working on It So Hopefully that Will Be Up Soon as Well We Also Have a Prototypical Implementation of Our Matches Library in Catch Does some Basic String Operations
- 47:49I'M Sure after I'Ve Finished this Talk I'M Going To Get Back to Working on It So Hopefully that Will Be Up Soon as Well We Also Have a Prototypical Implementation of Our Matches Library in Catch Does some Basic String Operations if You Didn't What Matches Are Have a Look at Something like Ham Crest There's Quite a Few Matches for Different Languages Just a Way of Writing Things That Are like Assertions but Can Do More Complex Comparisons I'M Still Undecided Actually whether Catch Really Needs Its Own Matches Library or if I Just Need To Provide Better Support for Incorporating Third-Party Metalo B's
- 52:10So You Are When the First Condition Matches Then You Have Multiple Independent Sub Tests or Serve the Question about Parallelizing Carol Eliza Yeah Two Independent Tests Followed the First One Yeah Catch Doesn't Currently Support That I Said the Primary Focus Is Unit Testing Where that Shouldn't Really Be an Issue but I Did Say that We Use Catch for Other Things As Well There Is a Bit of a Problem with Concurrency and Threading in General because of the Use of Singleton's behind the Scenes Something I'D Be Instead of Working On over Time To Try and Tease Out a Bit Better so It's Something That Hopefully Will Support in the Future but Right Now Not
- 52:43Something I'D Be Instead of Working On over Time To Try and Tease Out a Bit Better so It's Something That Hopefully Will Support in the Future but Right Now Not So What I Tend To Do in One or Two Times I'M Actually Had To Do this Do Heavily Multi-Threaded Tests When Actually on the Threads of Thought I'Ll Do My Testing outside of Catch Store the Results Somewhere and Then Just Assert on Them When I Joined Afterwards a Little Bit More Awkward but You Can Do It Yeah Here Regarding this Slide Can Individual Blocks Be Shared for Example You Copy and Paste at One of the Then Blocks I Think and They Were
- 53:06Outside of Catch Store the Results Somewhere and Then Just Assert on Them When I Joined Afterwards a Little Bit More Awkward but You Can Do It Yeah Here Regarding this Slide Can Individual Blocks Be Shared for Example You Copy and Paste at One of the Then Blocks I Think and They Were Yeah Sorry the Then Class I Think It Was You Copy and Pasted It Could You Also Put that into a Function and Then Just Call It from Somewhere Else and We'Ll Still Work or Do I Actually Have To in Paiste Can Call into Functions
- 53:30Yeah Sorry the Then Class I Think It Was You Copy and Pasted It Could You Also Put that into a Function and Then Just Call It from Somewhere Else and We'Ll Still Work or Do I Actually Have To in Paiste Can Call into Functions if There's Nothing Passed into these Tests so There's no Problem There One or Gotcha When You'Re Using a Helper Functions and Sections Is You Have To Remember this Rule about once They'Ve Seen a Section Once and You Know Completed It You Won't Go into Again so You Have a Section within a Function and You Have that Function Called Multiple Times It Might Be Surprising Sometimes that You Go into It and the Second Time It Doesn't Execute Your Section a Little Got You There but We Certainly Can Call into Functions and You Call for Whole Layers of Your Code and Come Back Again Maybe in a Call Back and Have an Assertion
- 55:30And that's a Great Example of One I'Ll Write the Code in Line because Then I Can Have both of Them Coexisting until I'M Ready To Replace One with the Other Blood Other than that There's no no Particularly Right or Wrong Way To Do It Sometimes When Doing Test-Driven Development It May Be Convenient To Use the Marking Framework Is It Possible to To Pick an Existing Marking Framework and Use It with Catch and if Not What Do You What Do You Suggest-. Yeah I Get Offset a Lot and I'Ve Never Really Been that Big on Mocking in C + + I Just Don't Find It's a Particularly Natural Fit for At Least the Way I Write Code in C + +
- 58:51It Is Something I'M Asked Quite a Lot There Is a Bit of a Problem in that We Can't Make Sections Work Exactly the Same Way as Test Cases in Terms of Discovery as You'Re Going through Where the Test Cases Are all Eagerly Registered up Front Using these Air Static Initializers with Sections It Discovers the Sections as It's Going through the Cones so It Has To Have Already Executed the Code up to a Point before It Can Determine whether that Section So if We Allow Tags in Sections and You Say Right Run Everything with this Tag Well You Won't Know that that Section Has It until It's Executed Test Case It Doesn't Have the Tag
- 1:00:14And after a While You Start You Continue Implementing and One of those Scenarios Fail Is There Possibility in Case of Debugging Sessions To Run this Scenario Isolated so the Scenario Corresponds to a Test Case They'Re Basically the Same Thing and on that Level You Can Specify an Individual Test Case or Scenario or Thereby Tag As Well so You Can Do It that Way but if You'Re Thinking of a Particular Branch for a Scenario So Down to a Given Then When that Has the Same Problem those Just Describing that We Can't Specify Individual Sections To Run or Individual Given When Names To Run
- 1:00:36And on that Level You Can Specify an Individual Test Case or Scenario or Thereby Tag As Well so You Can Do It that Way but if You'Re Thinking of a Particular Branch for a Scenario So Down to a Given Then When that Has the Same Problem those Just Describing that We Can't Specify Individual Sections To Run or Individual Given When Names To Run So Partially Yes I'M Also Interested in Bigger Test Run What's about Your Output Formats like Html or Xml Which You Can Output You Know What I Mean You Have To Have some Kind of Report
- 1:02:19You Can Extend with Your Own Reporters As Well so if You Wanted To Write an Html Reporter You Could and There Was Somebody Who Was Suggesting Writing a Team City Reporter As Well Which Could Be Quite Useful So Yes So One Big Advantage of Catch Is that You Can Express Your Test Cases Quite Naturally What I Have Never Liked So Far When Writing Test Cases Was Testing for Exceptions How Do You Handle those Right Yeah Okay Well There's a Lot of Other the Surgeon Matt Cruising Catch They Haven't Covered Just Scratching the Surface
- 1:05:29The Fact that They'Re Quite Rare Is Reassuring Things That Most People Are Running You Know Just Fine It's Usually the Various Different Versions of Gcc That Caused the Problem Particular Ones but Other than that No that's I'Ll See Running on the Mac It Sort Of You'Re Running on a Unix-Like System and It's Not Doing Anything Terribly Complicated so It Generally Runs Pretty Well There's Also a Maintained Fork for a Visual C + + 6 Which Should Consider Cross-Platform as Face and some of the Early Ball and Builders As Well My Questions Just One More Point Actually Someone Was Asking about Exceptions and I Remembered another Point There You Can Also Write Your Own Exception Handlers for Non-Standard Exception Based Exceptions so You Can Catch Them all in One Place and Translate Them into Your Own Message Has that Support Okay It's Their Support for Detecting Memory Leaks I for In in Example Four in Boost Test You Get at the End of Reporter for the Memory That Was Leaked
- 1:06:23So You Can Catch Them all in One Place and Translate Them into Your Own Message Has that Support Okay It's Their Support for Detecting Memory Leaks I for In in Example Four in Boost Test You Get at the End of Reporter for the Memory That Was Leaked but that Would Be Actually Nice Yeah that There Isn't Built In To Catch Partly because that's Very Platform Dependent My Day Job Again What I'Ve Done Is I'Ve Done the Leak Detection It Is Only like You Know Half a Screen Long and Then I Call Have My Own Version of Maine and I Call In To Catch Programmatically Which I Alluded to Being Able To Do that that Stuff Writing around Maine Is Documented








