DEV Community

Andew
Andew

Posted on

1

[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
`

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay