我为自动化测试下面的测试结构。
#/project/class/Calculator.rb
require 'TestModule'
require 'MathOperation'
class Calculator
include TestModule
include MathOperation
def initialize(num1, num2)
@num1 = num1
@num2 = num2
end
end
#/project/methods/MathOperation.rb
module MathOperation
def operation_addition
addition = @num1 + @num2
return addition
end
end
#/project/methods/TestModule.rb
module TestModule
def test_addition(value)
assert_equal 25, value
end
end
#/project/tescases/TestCalculator.rb
require 'minitest/autorun'
require 'calculator'
class TestCalculator < Minitest::Test
def setup
@calc = Calculator.new(15, 10)
end
def test_proper_addition
resolution = @calc.operation_addition
@calc.test_addition(resolution)
end
end
当我执行测试类TestCalculator我收到此错误。
NoMethodError: undefined method 'assert_equal' for #<Calculator:0x00000002a77518 @num1=15, @num2=10
当我用assert_equal
类方法TestCalculator
它的工作。 但是,这样一来会导致未来的长期测试案例和冗余代码。 我如何使用“断言”,在模块的类调用MINITEST? 可能吗?