Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > What is the standard way to put a standard set of asserts into acalled subroutine in test/unit?

Reply
Thread Tools

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

 
 
Xeno Campanoli / Eskimo North and Gmail
Guest
Posts: n/a
 
      04-30-2010
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
--
"It's the preponderance, stupid!" - Professor Stephen Schneider, IPCC member

 
Reply With Quote
 
 
 
 
Caleb Clausen
Guest
Posts: n/a
 
      04-30-2010
On 4/30/10, Xeno Campanoli / Eskimo North and Gmail
<> wrote:
> 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.

 
Reply With Quote
 
 
 
 
Phlip
Guest
Posts: n/a
 
      05-05-2010
On Apr 30, 2:42*pm, Xeno Campanoli / Eskimo North and Gmail
<xeno.campan...@gmail.com> wrote:
> 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!

--
Phlip
http://c2.com/cgi/wiki?ZeekLand
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
use one subroutine's variable value in another subroutine inside a module. king Perl Misc 5 04-29-2007 06:39 AM
redesigning JUnit asserts martinus Java 0 08-04-2006 07:10 AM
py.test munging strings in asserts? Timothy Grant Python 1 04-21-2006 07:30 AM
newbie Q: C's asserts in C++ KKramsch C++ 10 12-07-2004 08:27 AM
Java asserts in interfaces? Ken Java 5 05-22-2004 10:05 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57