Before/After Suite when using Ruby MiniTest Before/After Suite when using Ruby MiniTest ruby ruby

Before/After Suite when using Ruby MiniTest


There are setup() and teardown() methods available. The documentation also lists before() and after() as being available.

Edit: Are you looking to run something before each test or before or after the whole suite is finished?


As noted above in Caley's answer and comments, MiniTest::Unit contains the function after_tests. There is no before_tests or equivalent, but any code in your minitest_helper.rb file should be run before the test suite, so that will do the office of such a function.

Caveat: Still relatively new at Ruby, and very new at Minitest, so if I'm wrong, please correct me! :-)


To get this to work with the current version of Minitest (5.0.6) you need to require 'minitest' and use Minitest.after_run { ... }.

warn "MiniTest::Unit.after_tests is now Minitest.after_run. ..."

https://github.com/seattlerb/minitest/blob/master/lib/minitest.rbhttps://github.com/seattlerb/minitest/blob/master/lib/minitest/unit.rb