title: How to write output in the [ClassInitialize()] of a Unit Test class?
body: <p>I am writing some unit tests for the persistence layer of my C#.NET application. Before and after the tests of a test class execute, I want to do some <strong>cleaning up to erase possibly inserted dummy values</strong>, therefore, this cleaning up happens in methods marked with the attributes <code>[ClassInitialize()]</code> and <code>[ClassCleanup()]</code>.</p>
  
  <p><em>(I know that a better way would be to use an in-memory database, but it is not really doable so far as we depend on lots of stored procs....)</em> </p>
  
  <p>I would like to <strong>output some information about the results of the cleaning up</strong>, but I can not find a way to get the output in the test results with VISUAL Studio 2010. </p>
  
  <p>This is what I am doing so far :</p>
  
  <pre><code>        ///... lots of stuff before ...
  
          //global for the test run
          private static TestContext context;
  
          //for each test
          private IRepository repo;
  
          #region Initialisation and cleanup
  
          /// &lt;summary&gt;
          /// Execute once before the test-suite
          /// &lt;/summary&gt;
          [ClassInitialize()]
          public static void InitTestSuite(TestContext testContext)
          {
              context = testContext;    
              removeTestDataFromDb();    
          }
  
          [ClassCleanup()]
          public static void CleanupTestSuite()
          {
              removeTestDataFromDb();
          }
  
          private static void removeTestDataFromDb()
          {
              context.WriteLine("removeTestDataFromDb starting");
              using (ISession session = NHibernateHelper.OpenSession())
              {    
                  IDbConnection cn = session.Connection;
                  IDbCommand cmd = cn.CreateCommand();
                  //remove anyt test data
                  cmd.CommandText = @"DELETE FROM SomeTable
                      WHERE somefield LIKE 'easyToFindTestData%Test'";
                  int res = cmd.ExecuteNonQuery();    
                  context.WriteLine("removeTestDataFromDb done - affected {0} rows", res);
              }
          }
  
  
          [TestInitialize()]
          public void InitTest()
          {
              repo = new MyRepositoryImplementation();
          }
  
          [TestCleanup()]
          public void CleanupTest()
          {
              //cleanup       
              repo = null;
          }
  
          #endregion
  </code></pre>
  
  <p>I'm trying to use <strong>context.WriteLine()</strong> ... </p>
  
  <p>I also tried just using <strong>Console.WriteLine()</strong> with the same results. </p>
  
  <p><strong>How do you write to standard output in the <code>ClassInitialize</code> part and where can you access that output ?</strong></p>