Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Software quality with Code
Contracts and PEX
Sorin DAMIAN
Contracts
Design by Contract ™
Code contracts and runtime checking (Foxtrot)
Static verification (Clousot)
Documentati...
Design by contract
Described in articles since 1986
Around since the Eiffel language
Bertand Meyer
Analogy with busine...
Microsoft Code Contracts Library
Microsoft Research
Code contracts and runtime checking (Foxtrot)
Static checker (Clous...
Microsoft Code Contracts Tools
Runtime checking
 ccrewrite.exe
Static program verification
 cccheck.exe
Documentation...
Expressing contracts
Requirement and specification documents
Code comments
Guards / defensive programming
CodeContract...
Code Contracts
 Contracts vs. Validation
 Handling legacy code
 Pre and post conditions
 Documentation
 Handling cont...
Demo
using System.Diagnostics.Contracts;
Code Contracts
Preconditions
Legacy contracts
Post conditions
Invariants
Side effects and pure methods
Demo
Interfaces and contracts inheritance
Known issues
 Build slowdown due to the assembly rewriter
 No mechanism to provide contracts on delegates
 Static check...
Static verification
 Floyd-Hoare logic proposed in 1969
 Sir Charles Antony Richard Hoare
 Design by Contract
 Bertran...
Static verification
 Verification vs. Testing
 Abstract interpretation
 Working with existing projects
Pex Explorer
Pex Explorer
 Automated white box testing tool for .NET
 Parameterized unit tests
 Supports multiple frameworks
 Test ...
Input
• [runs the code +
monitors it]
Collects
observed
constraints
• [picks a branch]
Builds
constraints
system to solve
...
Pex Explorer
Demo
Pex understands your code
 Pex does not guess
 No random inputs
 No brute force
 Pex analyzes
 Partitions inputs into...
Q&A
Thank You!
And please fill the feedback forms 
Links
 http://research.microsoft.com/en-us/projects/contracts/
 http://research.microsoft.com/en-us/projects/pex/
 http...
Upcoming SlideShare
Loading in …5
×

Software quality with Code Contracts and PEX - CodeCamp16oct2010

1,313 views

Published on

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Software quality with Code Contracts and PEX - CodeCamp16oct2010

  1. 1. Software quality with Code Contracts and PEX Sorin DAMIAN
  2. 2. Contracts Design by Contract ™ Code contracts and runtime checking (Foxtrot) Static verification (Clousot) Documentation Automated unit testing (PEX)
  3. 3. Design by contract Described in articles since 1986 Around since the Eiffel language Bertand Meyer Analogy with business contracts Contracts Preconditions (What does the method expect?) Postconditions (What does it guarantee?) Invariants (What does it maintain?)
  4. 4. Microsoft Code Contracts Library Microsoft Research Code contracts and runtime checking (Foxtrot) Static checker (Clousot) Available for .NET 2.0 as an external assembly Included in .NET 4.0 Integration with Visual Studio 2008/2010 Available in all .NET programming languages
  5. 5. Microsoft Code Contracts Tools Runtime checking  ccrewrite.exe Static program verification  cccheck.exe Documentation generation  ccdoc.exe Automatic testing tools like PEX can take advantage of contracts
  6. 6. Expressing contracts Requirement and specification documents Code comments Guards / defensive programming CodeContracts Contract.Requires(arg != null); Contract.Ensures(Contract.Result<int>() > 0); Contract.Invariant(this.Total > 0); Assertions Assumptions
  7. 7. Code Contracts  Contracts vs. Validation  Handling legacy code  Pre and post conditions  Documentation  Handling contract failures  Contract violation events  Assert on contract failure  Contracts on interfaces and base classes  Contracts inheritance  Adding contracts to external libraries  Contract reference assemblies  Using a baseline for large projects
  8. 8. Demo using System.Diagnostics.Contracts;
  9. 9. Code Contracts Preconditions Legacy contracts Post conditions Invariants Side effects and pure methods
  10. 10. Demo Interfaces and contracts inheritance
  11. 11. Known issues  Build slowdown due to the assembly rewriter  No mechanism to provide contracts on delegates  Static checker doesn’t work with closures and yield iterators  You may get static checker errors for generated code  No edit and continue support
  12. 12. Static verification  Floyd-Hoare logic proposed in 1969  Sir Charles Antony Richard Hoare  Design by Contract  Bertrand Meyer  Spec#  Microsoft Research (credits go here..)  Code contracts library in .NET Framework 4.0
  13. 13. Static verification  Verification vs. Testing  Abstract interpretation  Working with existing projects
  14. 14. Pex Explorer
  15. 15. Pex Explorer  Automated white box testing tool for .NET  Parameterized unit tests  Supports multiple frameworks  Test cases for free!!!
  16. 16. Input • [runs the code + monitors it] Collects observed constraints • [picks a branch] Builds constraints system to solve • [solve “Z3”]
  17. 17. Pex Explorer
  18. 18. Demo
  19. 19. Pex understands your code  Pex does not guess  No random inputs  No brute force  Pex analyzes  Partitions inputs into equivalence classes  One equivalence class per branching behavior  Test inputs computed by Z3 (the constraint solver for program analysis from Microsoft Research)  Performs inter-procedural, path-sensitive analysis  Results:  Small test suite with high test coverage (new test == new branch in code)
  20. 20. Q&A
  21. 21. Thank You! And please fill the feedback forms 
  22. 22. Links  http://research.microsoft.com/en-us/projects/contracts/  http://research.microsoft.com/en-us/projects/pex/  http://pexforfun.com/  http://visualstudiogallery.msdn.microsoft.com/en-us/85f0aa38- a8a8-4811-8b86-e7f0b8d8c71b

×