locked
Assert outside of TestMethod... and not throw exception... RRS feed

  • Question

  • What I am trying to do is something similar to the old Assert methods. I want to fail the test, from the production, code without throwing an error back to the calling TestMethod or return a extra message.

    Something like this...

    public void MyMethod()
    {
      try
      {
        //Do stuff....
      }
      catch (Exception ex)
      {
        Assert.Fail(ex.Message);
        //Write to event log also.
        //Suppress error.
      } 
    }
    
    [TestMethod]
    public void MyMethodTest()
    {
      MyMethod();
    }

    However I get an error while trying this.

     

    Wednesday, July 7, 2010 2:53 PM

All replies

  • In NUnit I use this  technique which might be what you want. I assume it should still work in MSTest.
    Kevin
    Saturday, July 10, 2010 4:49 PM