logo       

Re: Use of ExpectedExceptionAttribute class in unit tests: msg#00077

windows.dotnet.nunit.devel

Subject: Re: Use of ExpectedExceptionAttribute class in unit tests

This is copy of the message I sent to the mailing list awhile back.
Attached are the changes I have implemented than. For sure this is not
polished enough, but demonstrates the idea, and will satisfy Boris's
requirements as well.

The patch is generated against then-current CVS version.

---------- Forwarded message ----------
From: Sunny <sloncho@xxxxxxxxx>
Date: Jul 21, 2005 7:14 PM
Subject: ExpectedException changes
To: nunit-developer@xxxxxxxxxxxxxxxxxxxxx


Hi,
As I wrote before, I needed this functionality, so I made some
modifications of ExpectedException test case handling. And a little
refactoring.

No regressions detected, all tests run OK.

The new stuff allows:

1. The Exception.Message to be tested with a regular expression. If
regular expression to be used, the expectedMessage parameter should
look like "{myRegExToBeTested}". This will allow to test only part of
the message for something. If the expectedException parameter is
string, which is not enclosed in figure brackets, then the whole
message is compared to that string, as it is currently.

[ExpectedException(typeof(AnyException), "This whole message have to
be equal")] - i.e. no change in the current behaviour.

or

[ExpectedException(typeof(AnyException), "{filename}"] - this will
test with Regex.IsMatch(ex.Message, "filename").

2. A custom property can be tested, either with a value object, or
using it's string representation (ToString() method) the same way, as
the Message property.

[ExpectedException(typeof(CustException), "CustProp", MyEnum.MyVal)] -
this will test if ex.CustProp == MyEnum.MyVal

[ExpectedException(typeof(CustException), "CustProp", "value1")] -
this will test if ex.CustProp.ToString() == "value1"

[ExpectedException(typeof(CustException), "CustProp", "{inf}")] - this
will test ex.CustProp.ToString() with the regex "inf".

I have added new test cases for this modifications. No old test case
was modified.

Please review attached patch. Comments are welcome.

This is my first time committing to FOSS, so maybe there is something
I did wrong, please put me in the right direction.

Cheers

--
Svetoslav Milenov (Sunny)

Attachment: nunit20.patch
Description: Binary data

<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise