locked
PexAssert.Throws in PUT in combination with Run Pex

    Question

  • Hi,

    when I create a PUT that calls a method of the class under test and attribute it with PexMethod, Run Pex will use this method and create automatic generated tests for it.

    This only works as long, as the call to the method is directly in the body of the PUT.

    Sample:

    This PUT is used by "Run Pex":

    [PexGenericArguments(typeof(string))]
    [PexGenericArguments(typeof(int))]
    [PexGenericArguments(typeof(object))]
    [PexMethod]
    public string Convert01_ConverterForTypeNotRegistered<T>(
        [PexAssumeUnderTest] ToStringConverter target, T objectToConvert)
    {
        var result = "";
        result = target.Convert(objectToConvert);
        return result;
    }

     

    This PUT not:

    [PexGenericArguments(typeof(string))]
    [PexGenericArguments(typeof(int))]
    [PexGenericArguments(typeof(object))]
    [PexMethod]
    public string Convert01_ConverterForTypeNotRegistered_ThrowsInvalidOperationException<T>(
        [PexAssumeUnderTest] ToStringConverter target, T objectToConvert)
    {
        var result = "";
        PexAssert.Throws<InvalidOperationException>(() => target.Convert(objectToConvert));
        return result;
    }

     

    I want to show, that a call to the method always throws this exception, independent of the parameters.

    How to achieve this?

     

    Regards

    Wednesday, February 16, 2011 5:19 PM

All replies