It's a good idea. You can implement this easily by making your attribute a subclass of TestDecoratorAttribute.
Just override the relevant SetUp / TearDown and other methods in your subclass. :) Jeff. On Mon, May 30, 2011 at 9:11 PM, Ron <[email protected]> wrote: > I'm using MbUnit/Gallio with Watin on a website that relies on tokens > to control functionality. There is a special back end user web service > for setting tokens without having using a full fledged browser...much > faster! > > Inside my test cases I'm finding that I'm doing a lot of lot the same > token prep work to get the user in the correct state before I hit the > site with a browser. I wrote some helper methods in a base class to > Revoke and Grant tokens: > > [Test] > public void SecuritiesReport_Run() > { > RevokeToken("foo"); // repeated a lot > GrantToken("bar"); // repeated a lot > > GoToSecuritiesReport(); > > // snip - use watin and other Asserts > } > > Is there a built-in class that provides one-off participation in SetUp > and TearDown? > > // is there anything like this in MbUnit ??? > public abstract class SetUpTearDownParticipantAttribute : Attribute > { > protected virtual void OnSetUp(TestContext context) > { > // optional > } > > protected virtual void OnTearDown(TestContext context) > { > // optional > } > } > > My thinking is that I could encapsulate some the repeated "busy prep > work" (like Grant/Revoke) into an attribute on _some_ test cases that > require the prep work: > > public class Ensure : SetUpTearDownParticipantAttribute > { > public string Token { get; set; } > > protected override void OnSetUp(TestContext context) > { > // assume these values will always exist > string baseUrl = context.Data.GetValue(new > Key<string>("BaseUrl")); > string userName = context.Data.GetValue(new > Key<string>("UserName")); > > // helper class that wraps WebClient > JsonWebClient.HttpPost(Token, "{0}/services/User.svc/{1}/ > tokens", baseUrl, userName); > } > } > > [Test] > [Ensure(Token = "bar")] > public void SecuritiesReport_Run() > { > GoToSecuritiesReport(); > > // snip - use watin > } > > The Ensure attribute can now be used across multiple fixtures without > remembering to add explicit method calls to the test body, without > having to inherit from a specific base class, and without having to > have an explicit SetUp function in each fixture class. > > Again, the goal of all this is to encapsulate the repeated setup code > so my watin test cases just contain things that need browser > automation. > > Good idea, bad idea, meh? > > -- > You received this message because you are subscribed to the Google Groups > "MbUnit.User" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/mbunituser?hl=en. > > -- You received this message because you are subscribed to the Google Groups "MbUnit.User" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/mbunituser?hl=en.
