Metodo 1: -Come conta affermazione sono calcolate in unità di prova
test.rb
class Test < Test::Unit::TestCase
def test_sample
assert_true(test)
assert_equal(a,b)
end
end
Risultato: - Finito in 38.329532529 secondi.
1 tests, 2 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
100% passed
Metodo 2: -
test.rb
class Test < Test::Unit::TestCase
require 'helper'
include AssertionHelper
def test_sample
test_assertion
end
end
helper.rb
include Test::Unit::Assertions
module AssertionHelper
def test_assertion
assert_true(test)
assert_equal(a,b)
end
end
Risultato: -
Finished in 38.329532529 seconds.
1 tests, 2 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
100% passed
Metodo 3: -
test.rb
class Test < Test::Unit::TestCase
require 'helper'
def test_sample
AssertionHelper.test_assertion()
end
end
helper.rb
include Test::Unit::Assertions
module AssertionHelper
def self.test_assertion
assert_true(test)
assert_equal(a,b)
end
end
Risultato: -
Finished in 38.329532529 seconds.
1 tests, 0 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
100% passed
Quando si utilizza il metodo 3, sto ottenendo conta come asserzione "0" anziché "2".
È possibile ottenere il conteggio delle asserzioni come 2 utilizzando il Metodo 2?
perché per avvolgere affermazione in un modulo separato ? – Anatoly
@Anatoly Ho dichiarazioni di asserzione comuni da verificare per più file di test. Quindi ho messo le asserzioni comuni in un file helper e chiamandolo dai file di test. – karan
test_helper.rb è per le funzioni comuni ma ** le asserzioni ** devono essere incluse nei test – Anatoly