Chapter 13 - Unit Testing

Exercise 1: Test assertions

We had a Minitest::Test subclass with a couple failing assertions. Here’s the same test, corrected so it’s passing:

require 'minitest/autorun'

class TestMath < Minitest::Test
  def test_addition
    assert(2 + 2 == 4)
  end

  def test_multiplication
    assert(3 * 4 == 12)
  end
end

Running the test produces this successful output:

Run options: --seed 12716

# Running:

..

Finished in 0.000889s, 2249.7188 runs/s, 2249.7188 assertions/s.

2 runs, 2 assertions, 0 failures, 0 errors, 0 skips