The Artima Developer Community
Sponsored Link

.NET Buzz Forum
Extending NUnit *easily* with version 2.2.1 (finally!)

0 replies.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a flat view of this topic  Flat View
Previous Topic   Next Topic
Threaded View: This topic has 0 replies on 1 page
Roy Osherove

Posts: 1807
Nickname: royo
Registered: Sep, 2003

Roy Osherove is a .Net consultant based in Israel
Extending NUnit *easily* with version 2.2.1 (finally!) Posted: Dec 4, 2004 5:30 PM
Reply to this message Reply

This post originated from an RSS feed registered with .NET Buzz by Roy Osherove.
Original Post: Extending NUnit *easily* with version 2.2.1 (finally!)
Feed Title: ISerializable
Feed URL: http://www.asp.net/err404.htm?aspxerrorpath=/rosherove/Rss.aspx
Feed Description: Roy Osherove's persistent thoughts
Latest .NET Buzz Posts
Latest .NET Buzz Posts by Roy Osherove
Latest Posts From ISerializable

I finally got some time so I sat down with the latest version of NUnit - 2.2.1 and tried using its extensibility features like the ability to create new custom test attributes that change test behavior, hopefully ridding myself of more complex projects that I had to do in the past (such as using interception or create a whole new binary version of Nunit just so that this could be done) .
I'm glad to say that it worked out great! NUnit 2.2.1 finally allows one to (no so)easily add custom attributes such as Rollback to NUnit without resorting to violence. Yey!
Unfortunately, the process is still too bureaucratic (for me at least), requiring the developer to add 3 new classes for each test attribute. I took it upon myself to check and see if this process could be made easier and it does :)
 
I basically created a base class you inherit from and does all the nasty work for you. Here's how easy it is to create a new attribute that does tracing on your unit tests:
 

[AttributeUsage(AttributeTargets.Method, AllowMultiple=false)]

[TestBuilder(typeof(CustomTestAttributeBase.CustomTestBuilder))]

public class SimpleTraceAttribute:CustomTestAttributeBase

{

   public override void BeforeTestRun (TestCaseResult testResult,

                                       TemplateTestCase testCase)

            {

                  Console.WriteLine("START: "+ testCase.Name);

            }

 

   public override void AfterTestRun (TestCaseResult testResult,

                                    TemplateTestCase testCase)

            {

                  Console.WriteLine("END: "+ testCase.Name);

            }

}

 
Simple and quick, no fuss.
 

Read: Extending NUnit *easily* with version 2.2.1 (finally!)


Topic: What's in a name? WSCF Previous Topic   Next Topic Topic: Symphony with SNDREC32.EXE

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use