CppCon 2017: Viktor Kirilov “Mix Tests and Production Code With Doctest...”

preview_player
Показать описание
Mix Tests and Production Code With Doctest - Implementing and Using the Fastest Modern C++ Testing Framework



Not a typical talk about testing. Here are some quotes from the Program Committee about it:

"Seeing a talk proposal about a new unit test framework made me quite skeptical. But then I looked at slides from one of the previous talks, and this looks very cool."
"I think others will be just as interested; this is just the kind of talk we want at the conference."
"Doing interesting and meaningful things in header-only libraries can be a fascinating topic, and this presentation appears to address some very interesting learnings from such an experience."
"The presentation is clearly well-prepared, having been given previously and iterated upon."

doctest is new to the C++ testing framework scene but is by far the fastest both in compile times (by orders of magnitude) and runtime compared to other such feature-rich alternatives.

It brings the ability of compiled languages such as D / Rust / Nim to have tests written directly in the production code by providing a fast, transparent and flexible test runner with a clean interface which can be removed entirely from the binary along with all tests for release builds of the software that are shipped to customers.

The framework can be used like any other even if you don't want/need to mix production code and tests - the list of features doesn't stop growing.

By attending this talk you will get familiar with the framework and see how it's different from all the rest.

To make things more interesting the presentation will not just focus on using the framework, but will delve into useful and generally applicable C++ techniques from its implementation for more than half the session length which can be applied in different areas of your work - like how to:

register code automatically before the program enters main()
decompose expressions with templates
translate exceptions - type-erased user-registerable translators
write a header-only library which compiles very very fast not at the cost of runtime performance
implement assert macros that don't result in code bloat
deal with warnings outside of the framework header - generated by code expanded from macros
loop a void owl once with while((void)0,0)

Viktor Kirilov: Bulgaria

With 3.5 years of professional experience with C++ in the games and VFX industries, Viktor currently spends his time writing open source software (since 01.01.2016). His interests are the making of games and game engines, high performance code, data oriented design, minimizing friction and incorporating good practices in the software development process such as testing and the use of modern tools like static analysis or instrumentation. Viktor is from Sofia, Bulgaria and his profession is his hobby.


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

I've been using doctest on a recent C++ 17 project. Call me a believer, tests right next to code has taken the reliability of my code to higher level, and I'm way more aware of side effects and edge cases than ever before. Great work, keep it up!

jjurksztowicz
Автор

Looks really nice.
I think mixing tests with production is great. Love that in Rust. :)
Good luck with the library!

TaiDesHen
Автор

I have been away from C++ for a number of years, having worked with Java and JUnit. I am pretty much married to the idea of TDD, so when I started working on a little C++ project of my own, it's now in my DNA to unit test the code. The arrangement of test cases and sub cases reminds me of the Jasmine or Karma test framework for Javascript, except easier to use. I just found out about Doctest and can't wait to get started using it.

MegaJohn
Автор

Interesting test library! Thanks for explaining it. It helps a lot.

TheLavaBlock
Автор

Manually forwarding types from standard library can be risky because in C++11 and higher both libstdc++ and libc++ add inline namespaces (like cxx11 or v1) for many types and you have no guarantee those will not change in the future. If you use pure std you may end up linking C++17 code against C++03 versions of those classes

pazdziochowaty
Автор

just tried it out -- looking forward to applying it in one somewhat-legacy code base :)

xealit
Автор

Good stuff, I was using Google Test, but this looks like it might be a far nicer thing to use for my projects.

titannick
Автор

Rather interesting testing framework - need to try it out. But I think it can be simplified. One idea is to replace macro "CHECK" with logging function, where log output is compared to reference file. See following youtube video:


This way it's possible to have production testing & instrumentation simultaneously, and by doing so minimize amount of written tests.

tpikaro
Автор

I hate Google Test. The macros are a real crap fest. The idea is not "tests as code" but instead it's "tests as macros" which defeats the entire purpose.

zyxyuv