How Do You Configure Pex to Respect Code Contracts?

后端 未结 5 1132
忘了有多久
忘了有多久 2021-01-02 16:13

Given the following example code, how can I configure Pex to respect my Code Contracts?

    public static IEnumerable Administrators(this UserGro         


        
5条回答
  •  情歌与酒
    2021-01-02 17:07

    First you need to use a typed version of Requires

    use ArgumentNullException as T

    Also in you project properties you need to tell code cotracts to use the standard rewriter. DO NOT click assert on failure ;)

    Contract.Requires(i != null);
    

    then your code will throw an argumetn null exception and pex can add an attribute to your pexmethod to say that it is allowed to throw it and will create a passing test that throws the exception

    you can then promote those and save the unit tests

提交回复
热议问题