Is there some clean and elegant way to execute my code right after a failed assert in ruby unit tests in Test::Unit, before teardown gets executed?
I am doing some automated GUI testing and would like to take a screenshot right after something failed.
If you’re on 1.9, don’t use Test::Unit::TestCase as your base class. Subclass it and override #run_test to rescue, take the screenshot and reraise:
Alternatively, and I think this is actually the most terse way in, you can use a before_teardown hook:
This won’t work on 1.8’s test/unit, but will with the minitest in 1.9.