[Mono-devel-list] Patch to use ExpectedException in Test XmlTextWriterTests
Duncan Mak
duncan at ximian.com
Wed Jul 2 18:42:22 EDT 2003
On Wed, 2003-07-02 at 10:15, Gert Driesen wrote:
> I don't think it's safe to change
>
> [Test]
> public void CommentInvalid ()
> {
> try {
> xtw.WriteComment("foo-");
> Fail("Should have thrown an ArgumentException.");
> }
> catch (ArgumentException) { }
>
> try {
> xtw.WriteComment("foo-->bar");
> Fail("Should have thrown an ArgumentException.");
> }
> catch (ArgumentException) { }
> }
>
> to
>
> [Test]
> [ExpectedException (typeof (ArgumentException))]
> public void CommentInvalid ()
> {
> xtw.WriteComment("foo-");
> xtw.WriteComment("foo-->bar");
> }
>
> The first test will only succeed if both method calls throw an
> ArgumentException, while the second test will succeed if either of
> these method calls will throw an ArgumentException.
I see that Martin has reverted his patch back to the original version,
with try/catch blocks.
I really like the new ExpectedExceptionAttribute.
Is it important that the two tests pass sequentially? If not, what about
something like this?
[Test] [ExpectedException (typeof (ArgumentException)]
public void CommentInvalid1 ()
{
xtw.WriteComment ("foo-");
}
[Test] [ExpectedException (typeof (ArgumentException)]
public void CommentInvalid2 ()
{
xtw.WriteComment ("foo-->bar");
}
If the two tests do need to be ran sequentially, I wonder if it's
possible to call another [Test] method within an existing [Test]
method... that might be one solution.
Duncan.
More information about the Mono-devel-list
mailing list