How Do You Configure Pex to Respect Code Contracts?

后端 未结 5 1129
忘了有多久
忘了有多久 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:08

    It violates the contracts on purpose to verify that an exception is thrown when the contract is violated. A lot of people will compile away the Requires methods in the Release build where some would say the edge cases should still be handled. It is also possible to write a custom contract failure handler which might not throw an exception or assertion failure. If you have a custom contract failure handler that doesn't prevent further execution you might cause even larger problems to happen further down the line.

    What Pex does do is write the tests that violate a contract so that it passes when an exception is thrown.

    TL/DR You shouldn't worry about it.

提交回复
热议问题