minitest

May 20, 2024

What is minitest?

minitest is a testing framework for Ruby.

Enabling XML Output

minitest can be configured to produce JUnit XML output by installing the minitest Ruby gem.

1gem install minitest

Then require and enable the minitest gem in your test code like this:

1# mixer.rb
2require 'minitest/autorun'
3require 'minitest/reporters'
4Minitest::Reporters.use! Minitest::Reporters::JUnitReporter.new('ruby/minitest/results', write_files: true)
5
6class ColorMixerTest < Minitest::Test
7 def test_red_and_blue
8 mixer = ColorMixer.new
9 assert mixer.mix('red', 'blue') == 'purple'
10 end
11end

Run it with bundle exec ruby ruby/minitest/mixer.rb and it will produce output that looks like this:

1<?xml version="1.0" encoding="UTF-8"?>
2<testsuites>
3 <testsuite name="ColorMixerTest" filepath="ruby/minitest/mixer.rb" skipped="0" failures="0" errors="0" tests="3" assertions="3" time="1.7999904230237007e-05">
4 <testcase name="test_red_and_yellow"
5 lineno="12"
6 classname="ColorMixerTest"
7 assertions="1"
8 time="1.0999967344105244e-05"
9 file="ruby/minitest/mixer.rb">
10 </testcase>
11 </testsuite>
12</testsuites>
13

Test Suite naming

The output file can be configured where you require minitest and use the JUnitReporter. The first argument to the constructor sets the output file.

1Minitest::Reporters.use! Minitest::Reporters::JUnitReporter
2 .new('ruby/minitest/results', write_files: true)

Handling Retries

minitest has an optional gem, minitest-optional_retry to automatically retry tests.

Other Configuration

See an example of using minitest in a GitHub action here.

Try it yourself or
request a demo

Get started for free

Try it yourself or
Request a Demo

Free for first 5 users