Test::Unit need help with assert

S

Shayne Bateman

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
 
S

Shayne Bateman

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
 
T

Timothy Goddard

Shayne said:
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

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.
 

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

Forum statistics

Threads
474,216
Messages
2,571,116
Members
47,720
Latest member
mohdkaif002

Latest Threads

Top