Testing exceptions with Approval Tests is very easy. Simply pass in a call to the function (usually wrapped in a lambda). Approval tests will execute the code, catch the exception, and verify the exception's message, i.e. exception.what()
.
The exception thrown must inherit std::exception
.
ApprovalTests::Approvals::verifyExceptionMessage([]() { /* your code goes here */ });
See ExceptionCollector.