Most Rust developers are familiar with “cargo test” and the default cargo test runner. It’s straight-forward API let’s developers write unit tests quickly and easily, because who wants to write tests if it feels like a chore? But what to do if the default test harness isn’t compatible with your specific build setup? In real-world scenarios like mixed Rust and C/C++ code bases this can often be the case, especially if CMake or another C/C++ toolchain drive the build.
In this talk, you’ll gain a deeper understanding of the parts involved in Rust’s default test runner and learn a robust pattern to build a custom test harness that is fully under your control. The talk covers how to replace Rust’s default test runner with the libtest-mimic crate and how to do test discovery using the linkme crate. The end goal is a test harness that is customizable and can be integrated with CMake and CTest or any other test setup.