c# - Multiple ClassCleanup Attributes per Test Class -


situation: of integration test classes share common approach setup scenarios in database hence provide abstract base class. takes care of full data cleanup @ end after tests ran:

public abstract class integrationtests {     ...     protected static void cleanup() { ... } } 

my inherited classes required call base method ensure base cleanup code runs:

[testclass] public class foointegrationtests : integrationtests {     ...      [classcleanup]     public static void foocleanup()     {         ...         cleanup();     } } 

issue: according msdn "[o]nly 1 method in class may decorated [the classcleanup] attribute" cannot decorate cleanup method base class , if did method wouldn't get called.

question: want solution which

  • always runs cleanup method base class without implementing in inherited classes, and
  • always runs custom cleanup method inheriting test class if there any.

i dislike force inheriting test class explicitly call base class have remember implement it. preferred more elegant yet simple(!) technique. ideas?

note: providing singleton base functionality shared test classes doesn't work because run tests on multiple test agents in parallel connected same database instance.

basing answer comments, calling classcleanup no longer in play.

i time in work. have peg base class testclass too, , "spend" cleanup , teardown attributes there. if need cleanup/teardown in derived class, make virtual method can ovveride whenever need them:

[testclass] public abstract class baseintegrationtest {     [testinitialize]     public void beforeeach() {         // stuff should happen before each unit test          basetestinitialize();     }      [testcleanup]     public void aftereach(){         // stuff should happen after each unit test          basetestcleanup();     }      public virtual void basetestinitialize() { }     public virtual void basetestcleanup() { } } 

with construct, have in integration test override basetestcleanup() such:

[testclass] public class derivedtestclass : baseingetrationtest {     public override void basetestcleanup()     {         // derived cleanup         base.basetestcleanup();     }       [testmethod]     public void somemethod_somecriteria_someresult()     {         // arrange          // act          // assert     } } 

Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -