# Test::Unit need help with assert

**URL:** <https://www.ruby-forum.com/t/test-unit-need-help-with-assert/73772>\
**Category:** Ruby\
**Created:** [October 26, 2006, 11:08pm UTC](https://www.ruby-forum.com/t/test-unit-need-help-with-assert/73772 "2006-10-26T23:08:58Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![quicksort](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/q/858c86/32.png) [@quicksort](https://www.ruby-forum.com/u/quicksort)\
**Post date:** [October 26, 2006, 11:08pm UTC](https://www.ruby-forum.com/t/test-unit-need-help-with-assert/73772/1 "2006-10-26T23:08:58Z")

</div>

Hi,  
I’m new to Ruby but have has some success bending it to my will. I am  
using the Test::Unit framework but it doesn’t quite fit my needs. I need  
to report the number of asserts() that pass and the number that fail.  
Also, I need failed asserts to not stop the program flow. Am I using  
the wrong test framework or can I easily bend Test::Unit to my needs?  
Thanks in advance!  
Shayne

---

<div class="post-metadata">

**Author:** ![quicksort](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/q/858c86/32.png) [@quicksort](https://www.ruby-forum.com/u/quicksort)\
**Post date:** [October 26, 2006, 11:23pm UTC](https://www.ruby-forum.com/t/test-unit-need-help-with-assert/73772/2 "2006-10-26T23:23:19Z")

</div>

Alright, I’m not too bright sometimes 🙂

I just realized the asserts are counted every time it runs and the final  
output tallies them all up.

So, the real question now is, how do I prevent a failed assert from  
stopping the testcase it is in?

Thanks

---

<div class="post-metadata">

**Author:** ![quicksort](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/q/858c86/32.png) [@quicksort](https://www.ruby-forum.com/u/quicksort)\
**Post date:** [October 26, 2006, 11:43pm UTC](https://www.ruby-forum.com/t/test-unit-need-help-with-assert/73772/3 "2006-10-26T23:43:00Z")

</div>

Shayne Bateman wrote:

> –  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

Unit tests aren’t meant for counting how many assertions fail, they’re  
meant to indicate where problems are so they can be fixed. You may want  
to divide your tests up further if you need fine grained details. If  
you absolutely have to do all tests you may want to do something like  
this:

…  
def test\_something  
failed = []  
failed \<\< :first\_test unless condition1  
failed \<\< :second\_test unless condition2  
assert failed == [], “#{failed.length} tests failed:  
#{failed.map{|e| e.to\_s}.join(', ')}”  
end  
…

If you’re trying to bend Ruby to your will then you’re thinking wrong.

---

<div class="post-metadata">

**Author:** ![quicksort](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/q/858c86/32.png) [@quicksort](https://www.ruby-forum.com/u/quicksort)\
**Post date:** [October 27, 2006, 9:11am UTC](https://www.ruby-forum.com/t/test-unit-need-help-with-assert/73772/4 "2006-10-27T09:11:11Z")

</div>

Shayne Bateman schrieb:

> Also, I need failed asserts to not stop the program flow. Am I using  
> the wrong test framework or can I easily bend Test::Unit to my needs?

Shayne, maybe this gives you some ideas:

[http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/138320](http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/138320)

Regards,  
Pit

---

<div class="post-metadata">

**Author:** ![quicksort](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/q/858c86/32.png) [@quicksort](https://www.ruby-forum.com/u/quicksort)\
**Post date:** [October 27, 2006, 6:17pm UTC](https://www.ruby-forum.com/t/test-unit-need-help-with-assert/73772/5 "2006-10-27T18:17:43Z")

</div>

Pit C. wrote:

> Shayne, maybe this gives you some ideas:
> 
> [http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/138320](http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/138320)
> 
> Regards,  
> Pit

That was right on the money. Thanks
