Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do i need to use minitest/autorun?

Why do i require minitest/autorun instead of test/unit for generating unit test

require 'test/unit'

class Brokened
  def uh_oh
    "I needs fixing"
  end
end

class BrokenedTest < Minitest::Test
  def test_uh_of
    actual = Brokened.new
    assert_equal("I'm all better now", actual.uh_oh)
  end
end

Running the above code, interpreter raise warning

You should require 'minitest/autorun' instead

like image 962
Rajnish Avatar asked Dec 16 '15 17:12

Rajnish


1 Answers

Your code example will end in a NameError: uninitialized constant Minitest.

You have two possibilities:

  • Use test/unit in combination with Test::Unit::TestCase or
  • use require 'minitest/autorun' in combination with Minitest::Test.

test/unit is deprecated and it is recommended to use minitest (MiniTest is faster and smaller).

If you switch the test gem you must change perhaps some more things:

  • replace require "test/unit" with require "minitest/autorun"
  • replace Test::Unit::TestCase with with Minitest::Test
  • There is no assert_nothing_raised (details)
  • assert_raise becomes assert_raises.
  • perhaps some other issues

You may use require 'minitest' instead require 'minitest/autorun' - you will get no syntax error, but there is also no test execution. If you want to execute tests, you must call them on your own (see minitest-a-test-suite-with-method-level-granularity)

like image 112
knut Avatar answered Oct 20 '22 05:10

knut