Created
September 20, 2017 05:38
-
-
Save koduki/4fb27b935e3e33969907c4983ee7f54e to your computer and use it in GitHub Desktop.
Unit-Test library example for govy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module TestOperations | |
def test(case_name) | |
@case_name = case_name | |
r = yield | |
if r != nil | |
if @cnt_failed == nil | |
@cnt_failed = 0 | |
end | |
@cnt_failed += 1 | |
msg = "" | |
msg += @cnt_failed.to_s + ") Failure:" + "\n" | |
msg += r[:case] + ":" + "\n" | |
msg += "Expected: " + r[:expect] + "\n" | |
msg += " Actual: " + r[:actual] + "\n" | |
msg += "\n" | |
puts msg | |
end | |
end | |
def assert_equal(expect, actual) | |
if @cnt_assertions == nil | |
@cnt_assertions = 0 | |
end | |
@cnt_assertions += 1 | |
if expect != actual | |
{expect: expect.to_s, actual: actual.to_s, case: @case_name } | |
else | |
nil | |
end | |
end | |
end | |
class Test | |
extend TestOperations | |
def initialize | |
end | |
def self.show_report | |
puts @cnt_assertions.to_s + " assertions, " + @cnt_failed.to_s + " failures" | |
end | |
end | |
class MyTest < Test | |
test "tese case 001" do | |
assert_equal(1, 2) | |
end | |
test "tese case 002" do | |
assert_equal(3, 4) | |
end | |
test "tese case 003" do | |
assert_equal(3, 3) | |
end | |
end | |
MyTest.show_report |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
$ govy -e simple_test.gb