Re: [easyb-users] Verifying attributes of exceptions

31 views
Skip to first unread message

Andrew Glover

unread,
Aug 29, 2012, 9:14:12 AM8/29/12
to easyb...@googlegroups.com
You could put the code under test in a try/catch block and in the catch, assert various aspects of the caught exception. ex.getMessage().should etc...

Sent from my iPad

On Aug 29, 2012, at 6:51 AM, David Snowsill <david.s...@calibreft.com.au> wrote:

I am a new user to easyb and was wondering if anybody can provide some guidance on how to verify the attributes of a thrown exception.

I can check that the exception is thrown using ensureThrows but how do I check that the message of the exception i.e. ex.getMessage() contains some specific text?

My then clause looks as follows:

    then "Exception should be thrown with details of invalid subject", 
    {
        ensureThrows(Exception)
        {
            factory.create(aCalculatedGroup)
        }
    }

Thanks,

David

--
You received this message because you are subscribed to the Google Groups "Easyb Users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/easyb-users/-/TDOcDwtwBY4J.
To post to this group, send email to easyb...@googlegroups.com.
To unsubscribe from this group, send email to easyb-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/easyb-users?hl=en.

Dave Newton

unread,
Aug 29, 2012, 9:28:53 AM8/29/12
to easyb...@googlegroups.com
I'd add that I wonder what's actually being tested.

This sounds more like a case for an exception class that takes the information as ctor/builder arguments and constructs the message from that data.

Rather than testing behavior by parsing out a string, test the exception on its own, and test the class you're talking about here by making sure it throws an exception of the appropriate type.

I might be misinterpreting, though.

Dave
Reply all
Reply to author
Forward
0 new messages