Question

I have a utility class that takes a constructor parameter of an interface to a repository class. This then gets assigned to a private field in the class. In various methods in the class I reference this interface private to do things.

I then ran Pex against this class and am getting a whole heap of null reference exceptions being thrown. After investigating this I found a attribute named PexAssumeNotNull. I have placed this agsint the constructor parameter and the private field to try and get around this problem. I have also added a null check in the constructor which throws a ArgumentNullException exception when a null is passed into the constructor.

I have now re-run the Pex Explorations over this class and am still getting the null reference exceptions.

My question is what do i need to do to not get these exceptions? Do I need to recreated the pex test classes and if so how do I do this?

Was it helpful?

Solution

Use PexAssume.IsNotNull in the right places. A very flexible solution.

This also allows for arbitrary conditions like someString.Length >= 3

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top