I am running a test where a usb device is opened, a packet is sent and received and it is closed again. It looks like this:
void TestCase1(void) { int recv; BOOST_REQUIRE(initDevice()); BOOST_REQUIRE(openDevice()); BOOST_REQUIRE_EQUAL(receiveData(), 5); BOOST_REQUIRE(closeDevice()); BOOST_REQUIRE(uninitDevice()); } Now whenever there is an error in the receiveData() call and the Check for '5' fails, the closeDevice() and uninitDevice() are not called anymore and I cannot use the device in the next test. Is there a way to handle this? Maybe catch an exception and close and uninit the device in that catch scope too? Or is this a complete wrong approach? I am pretty new to unit testing. So any help is appreciated. Thanks!