문제

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?

도움이 되었습니까?

해결책

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

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top