Your SlideShare is downloading. ×
Software quality with Code Contracts and PEX - CodeCamp16oct2010
Software quality with Code Contracts and PEX - CodeCamp16oct2010
Software quality with Code Contracts and PEX - CodeCamp16oct2010
Software quality with Code Contracts and PEX - CodeCamp16oct2010
Software quality with Code Contracts and PEX - CodeCamp16oct2010
Software quality with Code Contracts and PEX - CodeCamp16oct2010
Software quality with Code Contracts and PEX - CodeCamp16oct2010
Software quality with Code Contracts and PEX - CodeCamp16oct2010
Software quality with Code Contracts and PEX - CodeCamp16oct2010
Software quality with Code Contracts and PEX - CodeCamp16oct2010
Software quality with Code Contracts and PEX - CodeCamp16oct2010
Software quality with Code Contracts and PEX - CodeCamp16oct2010
Software quality with Code Contracts and PEX - CodeCamp16oct2010
Software quality with Code Contracts and PEX - CodeCamp16oct2010
Software quality with Code Contracts and PEX - CodeCamp16oct2010
Software quality with Code Contracts and PEX - CodeCamp16oct2010
Software quality with Code Contracts and PEX - CodeCamp16oct2010
Software quality with Code Contracts and PEX - CodeCamp16oct2010
Software quality with Code Contracts and PEX - CodeCamp16oct2010
Software quality with Code Contracts and PEX - CodeCamp16oct2010
Software quality with Code Contracts and PEX - CodeCamp16oct2010
Software quality with Code Contracts and PEX - CodeCamp16oct2010
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Software quality with Code Contracts and PEX - CodeCamp16oct2010

1,051

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
1,051
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
21
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide
  • Design by Contract (DbC) or Programming by Contract is an approach to designing computer software. It prescribes that software designers should define formal, precise and verifiable interface specifications for software components, which extend the ordinary definition of abstract data types with preconditions, postconditions and invariants. These specifications are referred to as "contracts", in accordance with a conceptual metaphor with the conditions and obligations of business contracts.

    http://en.wikipedia.org/wiki/Design_by_contract
  • Language agnostic static checking is achieved though Clousot, which is an abstract intepretation-based static analyzer for the analysis of .NET assemblies. It contains abstract domains for checking out-of-bounds array accesses, null dereferences, string usage, and memory accesses in unsafe managed code. It can statically validate Foxtrot contracts.
  • Reference assemblies: C:\Program Files (x86)\Microsoft\Contracts\Contracts\v3.5
    Samples: C:\Program Files (x86)\Microsoft\Contracts\Samples
  • Snippets
  • http://pexforfun.com/Default.aspx?language=CSharp&sample=AbsVerified
  • Hoare logic (also known as Floyd–Hoare logic or Hoare rules) is a formal system with a set of logical rules for reasoning rigorously about the correctness of computer programs. It was proposed in 1969 by the British computer scientist and logician C. A. R. Hoare, and subsequently refined by Hoare and other researchers.[1] The original ideas were seeded by the work of Robert Floyd, who had published a similar system[2] for flowcharts.

    ACM Turing Award for "fundamental contributions to the definition and design of programming languages".
  • Transcript

    • 1. Software quality with Code Contracts and PEX Sorin DAMIAN
    • 2. Contracts Design by Contract ™ Code contracts and runtime checking (Foxtrot) Static verification (Clousot) Documentation Automated unit testing (PEX)
    • 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. 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. 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. 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. 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. Demo using System.Diagnostics.Contracts;
    • 9. Code Contracts Preconditions Legacy contracts Post conditions Invariants Side effects and pure methods
    • 10. Demo Interfaces and contracts inheritance
    • 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. 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. Static verification  Verification vs. Testing  Abstract interpretation  Working with existing projects
    • 14. Pex Explorer
    • 15. Pex Explorer  Automated white box testing tool for .NET  Parameterized unit tests  Supports multiple frameworks  Test cases for free!!!
    • 16. Input • [runs the code + monitors it] Collects observed constraints • [picks a branch] Builds constraints system to solve • [solve “Z3”]
    • 17. Pex Explorer
    • 18. Demo
    • 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. Q&A
    • 21. Thank You! And please fill the feedback forms 
    • 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

    ×