|
Re: Use of ExpectedExceptionAttribute class in unit tests: msg#00077windows.dotnet.nunit.devel
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)
|
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Re: Use of ExpectedExceptionAttribute class in unit tests: 00077, Sunny |
|---|---|
| Next by Date: | Ann: NUnit 2.2.5 Release: 00077, Charlie Poole |
| Previous by Thread: | Re: Use of ExpectedExceptionAttribute class in unit testsi: 00077, Sunny |
| Next by Thread: | Re: [XP] Ann: NUnit 2.2.4 Production Release: 00077, Sam Gentile |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |