[prev in list] [next in list] [prev in thread] [next in thread] 

List:       mono-devel-list
Subject:    RE: [mono-devel-list] System.Drawing.Pens test patch
From:       Ben Maurer <bmaurer () ximian ! com>
Date:       2005-07-31 15:20:35
Message-ID: 1122823235.7868.7.camel () localhost ! localdomain
[Download RAW message or body]

On Sun, 2005-07-31 at 05:56 -0700, Andrew Skiba wrote:
> Hi.
> 
> In many tests in System.Drawing there is a strange construct like:
> 
> try {
> 	Do.Something ();
> 	Fail ("This should throw ArgumentException");
> }
> catch (Exception e) {
> 	Assert ("MSG", e is ArgumentException);
> }
> 
> Problem with this approach is that catch will take care of all
> exceptions and then rethrow nunit assertion exception via Assert (...).
> The source and the call stack of original exception will be lost. So I
> changed it to:
> 
> catch (ArgumentException) {
> 	Assert ("MSG", true);
> }
> 
> In this way, if e is not argument exception, its contents will be seen
> in TestResults.xml, together with the whole call stack.
> 
> I'm not sure if there is any use of Assert ("MSG", true), may be it can
> be omitted?
> 
> While it would be best to fix all such places, I changed only those I
> needed right now, and the rest can be done later.

The cleanest way to do these is to factor each out into a different
method and use the ExpectedException attribute. First, this is much
cleaner. Second, both the old code and your suggestion don't do as much
checking as possible. ArgumentException is a base class for other
exceptions.

benm@alpha:~$ monop ArgumentOutOfRangeException
[Serializable]
public class ArgumentOutOfRangeException : ArgumentException, \
System.Runtime.Serialization.ISerializable {

With ExpectedException, nunit tests the exception thrown is of the
*exact* type specified in the attribute. However the "is blah" tests and
the catch (Blah) clauses catch any derived types. So, they are not as
good of tests.

-- Ben

_______________________________________________
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic