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

**URL:** <https://www.ruby-forum.com/t/what-is-the-standard-way-to-put-a-standard-set-of-asserts-into-a-called-subroutine-in-test-unit/187888>\
**Category:** Ruby\
**Created:** [April 30, 2010, 11:44pm UTC](https://www.ruby-forum.com/t/what-is-the-standard-way-to-put-a-standard-set-of-asserts-into-a-called-subroutine-in-test-unit/187888 "2010-04-30T23:44:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Xeno\_CSS\_Eskimo\_No](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/a9a28c/32.png) [@Xeno\_CSS\_Eskimo\_No](https://www.ruby-forum.com/u/Xeno_CSS_Eskimo_No)\
**Post date:** [April 30, 2010, 11:44pm UTC](https://www.ruby-forum.com/t/what-is-the-standard-way-to-put-a-standard-set-of-asserts-into-a-called-subroutine-in-test-unit/187888/1 "2010-04-30T23:44:22Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Xeno\_CSS\_Eskimo\_No](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/a9a28c/32.png) [@Xeno\_CSS\_Eskimo\_No](https://www.ruby-forum.com/u/Xeno_CSS_Eskimo_No)\
**Post date:** [May 1, 2010, 12:48am UTC](https://www.ruby-forum.com/t/what-is-the-standard-way-to-put-a-standard-set-of-asserts-into-a-called-subroutine-in-test-unit/187888/2 "2010-05-01T00:48:10Z")

</div>

On 4/30/10, Xeno C. / Eskimo North and Gmail  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> end
> 
> def test\_my\_stuff  
> mysub(X,Y)  
> end
> 
> end

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

---

<div class="post-metadata">

**Author:** ![Xeno\_CSS\_Eskimo\_No](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/a9a28c/32.png) [@Xeno\_CSS\_Eskimo\_No](https://www.ruby-forum.com/u/Xeno_CSS_Eskimo_No)\
**Post date:** [May 6, 2010, 12:45am UTC](https://www.ruby-forum.com/t/what-is-the-standard-way-to-put-a-standard-set-of-asserts-into-a-called-subroutine-in-test-unit/187888/3 "2010-05-06T00:45:30Z")

</div>

On Apr 30, 2:42 pm, Xeno C. / Eskimo North and Gmail  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ```
> 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!😉
