4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[Ruby]minitestの基本

Posted at

minitestとは

Rubyのテスティングフレームワーク
GitHub
rdoc

インストール

$ gem install minitest

テストコード

テスト対象

calc.rb
def add(a, b)
  a + b
end

def subtract(a, b)
  a - b
end

def multiply(a, b)
  a * b
end

def divide(a, b)
  a / b
end

テストコード
Minitestは「test_」で始まるメソッドを順次実行する。

calc_test.rb
require 'minitest/autorun'
require './lib/calc'

class CalcTest < Minitest::Test
  def test_add
    assert_equal 3, add(1, 2)
  end

  def test_subtract
    assert_equal 1, subtract(2, 1)
  end

  def test_multiply
    assert_equal 2, multiply(1, 2)
  end

  def test_divide
    assert_equal 2, divide(4, 2)
  end
end

実行結果

# Running:

....

Finished in 0.000907s, 4410.1437 runs/s, 4410.1437 assertions/s.
4 runs, 4 assertions, 0 failures, 0 errors, 0 skips
4
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?