title: How do I implement AssemblyInitialize/AssemblyCleanup in my CodedUITest in MSVS 2010?
body: <p>I am trying to implement <em>AssemblyInitialize/AssemblyCleanup</em> attributes in my Microsoft Visual Studio 2010 for the exact purpose as stated <a href="http://codesmartnothard.com/MoreEfficientCodedUITestsWithClassInitialize.aspx" rel="nofollow">here</a>. That link even describes the process which I need to follow to implement the code. </p>
  
  <p>A quick summary of that purpose is to create an initial block of code which will run right before any test no matter which of the codedUITests I run in the solution and then a block of code which will run after the last codedUITest is completed. Example: I need to open up a specific application, then run a series of codedUITests which all start at that application and which are executed in any order, then close the application after everything is finished; this is more efficient than opening/closing the application for each codedUITest.</p>
  
  <p>What I don't understand is where I need to place the code laid out at the bottom of that page (also shown below). I stuck all that code right under my 'public partial class UIMap' and the code runs except it runs the 'OpenApplication' and 'CloseApplication' commands before/after each CodedUITest instead of sandwiching the entire group of CodedUITests.</p>
  
  <p>How do I implement the code correctly?</p>
  
  <p><em>Update:</em></p>
  
  <blockquote>
    <p>I discovered AssemblyI/C last night and I spent 3 hours trying to
    figure out where to put the code so it works. If I put the
    AssemblyInitialize at the beginning of a specific test method then:</p>
    
    <p>1) It still wouldn't run - it was giving me some error saying that
    UIMap.OpenWindow() and UIMap.CloseWindow() methods need to be static
    and I couldn't figure out how to make them static.</p>
    
    <p>2) Wouldn't the specific [TestMethod] which has the AssemblyI/C on it
    need to be in the test set? In my situation I have a dozen
    CodedUITests which need to run either individually or in a larger
    group and I need to get the AssemblyI/C to Open/Close the window I am
    testing.</p>
  </blockquote>