What is the standard way to put a standard set of asserts into acalled subroutine in test/unit?

  • Thread starter Xeno Campanoli / Eskimo North and Gmail
  • Start date
X

Xeno Campanoli / Eskimo North and Gmail

I want to do something like:

require 'test/unit'

class TestMyStuff < Test::Unit::TestCase

def mysub(x,y)
assert_not_nil(x,"x nil")
assert_not_nil(y,"y nil")
assert(x == y,"messages")
end

def test_my_stuff
mysub(X,Y)
end

end
 
C

Caleb Clausen

I want to do something like:

require 'test/unit'

class TestMyStuff < Test::Unit::TestCase

def mysub(x,y)
assert_not_nil(x,"x nil")
assert_not_nil(y,"y nil")
assert(x == y,"messages")
end

def test_my_stuff
mysub(X,Y)
end

end

Yes, and? That works perfectly for me. I do it all the time.
 
P

Phlip

I want to do something like:

require 'test/unit'

class TestMyStuff < Test::Unit::TestCase

        def mysub(x,y)
                assert_not_nil(x,"x nil")
                assert_not_nil(y,"y nil")
                assert(x == y,"messages")
        end

Call it assert_mysub().

In general, generic assertions have mundane names, such as
assert_equal, and application-specific assertions have long names that
reveal their application-specific intent. Such as assert_x_and_y.

Next, all tests use the pattern Assemble, Activate, Assert, but your
test case might be missing its Activate line. The line that actually
does something important, in your production code! That pattern is,
generally, why I always call the assembly methods "assemble_", and I
always call assertions "assert_".

And, as always, props for writing developer tests. You are now among
the top 5% of all programmers. (More's the pity!;)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top