[Today I learned] Minitest

andrewp

Andew

Posted on February 6, 2024

[Today I learned] Minitest

Minitest, a testing framework included with Ruby, is used to validate that our code behaves as expected under various conditions.
`

calculator.rb

class Calculator
def add(a, b)
a + b
end
end

tests/test_calculator.rb

require 'minitest/autorun'
require './calculator'

class TestCalculator < Minitest::Test
def test_addition
calculator = Calculator.new
assert_equal 4, calculator.add(2, 2), "Addition method failed"
end
end
`

💖 💪 🙅 🚩
andrewp
Andew

Posted on February 6, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

[Today I learned] Minitest
ruby [Today I learned] Minitest

February 6, 2024