'unit'_test: Implementing a Macro-free Unit Testing Framework from Scratch in C++20 - Kris Jusiak

preview_player
Показать описание
---
Testing in C++ is not easy, it often requires a lot of boilerplate code, macro usage, and/or understanding of complicated testing frameworks.
But it doesn't have to be like that. C++20 will enable us to reinvent the way we write tests!

In this case study, we will address the difficulty of testing with C++ by implementing a new, fully functional, macro-free testing framework 1 from scratch with modern C++20 features to make the following snippet compile and run:

01 import ut;
02
03 int main() {
04 "fib"_test = [] { // Running "fib"...
06 }; // tests: 1 | 1 failed
07 } // asserts: 1 | 0 passed | 1 failed

At the end of this session, the audience will have a better understanding of C++20 features such as:
- Modules
- Concepts
- Source Location
- New additions to lambdas
- User-Defined Literals

Additionally, attendees will get familiar with an expressive way of testing with modern C++ based on UT - Unit Testing Framework [2].

Let's get ready to follow the Beyonce rule - 'If you liked it then you "should put a"_test on it' and test all the things at CppCon 2021!

---
Kris Jusiak

Kris is a Software Architect passionate about programming and who has worked in different industries over the years including telecommunications, games and most recently finance for Quantlab Financial, LLC. He has an interest in modern C++ development with a focus on performance and quality. He is an open-source enthusiast with multiple open-source libraries where he uses template meta-programming techniques to support the C++ rule - "Don't pay for what you don't use" whilst trying to be as declarative as possible with a help of domain-specific languages. Kris is also a keen advocate of extreme programming techniques, Test/Behavior Driven Development and truly believes that 'the only way to go fast is to go well!'.

---

*--*
Рекомендации по теме
Комментарии
Автор

I immediately switched my project from catch2 to UT after this talk

discreet_boson
Автор

A refreshing look on unit testing frameworks!

petermuller
Автор

Amazing library! Thanks for the great talk!

dimeterious_fox
Автор

One concern I have with this is that if you are testing something (say MyFunc() == 3_i) and you forget to write the _i it will resolve to a normal comparison, which means you're not actually testing anything. There might be a warning maybe.. but is that enough? It seems a bit dangerous to write tests that don't actually test anything. I wonder if that can be improved somehow

ruadeil_zabelin
Автор

I am really triggered by the missing " before unit on the YouTube thumbnail xD

petermuller
Автор

C++ developers were so preoccupied with whether or not they could [use metaprogramming to write a test framework] that they that they didn't stop to think if they should

asklar