Forum: Ruby on Rails Unit Tests Behavior

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Af93ba6b6b59f22a8f37e8de5702ef98?d=identicon&s=25 Bob Silva (Guest)
on 2006-01-28 07:47
(Received via mailing list)
Hi,



Working on unit tests and I have a few cascade delete constraints I am
testing.



The unit tests stop at the first assert_raise test. Is this typical?





def test_destroy_all_cascade_delete

    assert_equal 1, Iep.find(:first).client_id

    assert_equal 1, Encounter.find(:first).client_id

    @client.destroy

    assert_raise(ActiveRecord::RecordNotFound) { Iep.find(1) }    <--
Stops
testing here

    assert_raise(ActiveRecord::RecordNotFound) { Encounter.find(1) }

end



So if I comment out the client.destroy call, the first assert_raise
fails
and the unit test doesn't try the next one.



Thanks





Bob Silva

http://www.railtie.net/
58479f76374a3ba3c69b9804163f39f4?d=identicon&s=25 Eric Hodel (Guest)
on 2006-01-30 02:43
(Received via mailing list)
On Jan 27, 2006, at 10:48 PM, Bob Silva wrote:

> The unit tests stop at the first assert_raise test. Is this typical?

Test::Unit stops at the first failed assertion.

Rather than writing large tests testing every code path, create a
test method per code path.  It lets you find failures easier.
(Multiple failures in one suite run rather than multiple suite runs
fixing as you go, less time context switching between editing and
running.)

If you have code common to multiple tests refactor them into methods.

If you have code common to multiple test cases refactor them into an
abstract test class.

--
Eric Hodel - drbrain@segment7.net - http://segment7.net
This implementation is HODEL-HASH-9600 compliant

http://trackmap.robotcoop.com
This topic is locked and can not be replied to.