AssertFailedException in NUnit tests? RRS feed

  • Question

  • I've tried to follow the quick start tutorial on Pex+Code Contracts, just with one modification: I used NUnit instead of MSUnit (NUnit is correctly setup in Pex options and everything works fine without Contracts). This is my method:

    public static string TrimAfter(string value, string suffix)
    	Contract.Requires(value != null);
    	int index = value.IndexOf(suffix);
    	if (index < 0)
    		return value;
    	return value.Substring(0, index);

    Explorations run fine but after I save them as unit tests, the solution doesn't compile as some test cases look like this:

    public void TrimAfterThrowsContractException946()
       string s;
       s = this.TrimAfter("", (string)null);
       throw new AssertFailedException();
      catch(Exception ex)
       if (!PexContract.IsContractException(ex))
        throw ex;

    Is that a known issue or am I doing something wrong?





    Thursday, June 10, 2010 4:09 PM


  • Hi Borek,

    This is a bug in our interface with NUnit. We emit the incorrect exception type name. Until we fix this code generation issue, you could work around the problem by defining the NUnit.Framework.AssertFailedException exception type in your test project so that it compiles.

    Thanks for your feedback, Peli.

    Jonathan "Peli" de Halleux - Like Pex and Moles on Facebook!
    • Marked as answer by Borek Bernard Thursday, June 10, 2010 7:25 PM
    Thursday, June 10, 2010 5:21 PM