Running test/unit suites with Minitest

Sometimes it happens that you want to run an old test suite, but you don’t have a correct version of the testing framework available. That happens a lot in Fedora
since tooling around RPM supports only one version of each component and new rubies does not come with test/unit anymore. As we still need to run the tests, we have two options. Either go ahead and update the whole test suite to a new version or just use Ruby’s dynamic nature to actually run it. Let’s look how the latter can look like.

Here’s an example of running Builder’s tests against latest Ruby 2.2.2 and Minitest 4:

First we need to tell Ruby to require minitest/autorun, which will run our tests using Minitest automatically, and to include the /lib and /test paths on $LOAD_PATH so the requires from the tests itself can require Builder. Afterwards we rewrite the Kernel.require() method so it does not load test/unit. Once we have all that, we are ready to replace Test constant with Minitest one and then include methods like assert_not_nil and assert_nothing_raised that are not part of Minitest 4. We also rename assert_raise to assert_raises.

Finally we iterate over test files and require them. The result is as expected:

Leave a comment

Your email address will not be published. Required fields are marked *