pex
DESCRIPTION
DDD7http://blog.benhall.me.uk/2008/11/ddd7-slides-and-code-pex-future-of-unit.htmlTRANSCRIPT
![Page 2: Pex](https://reader033.vdocuments.mx/reader033/viewer/2022061216/54b3b2454a79597f5f8b4637/html5/thumbnails/2.jpg)
Agenda
• What is Pex?• Problem Pex is trying to solve• Pex in the Real World• The future?
![Page 3: Pex](https://reader033.vdocuments.mx/reader033/viewer/2022061216/54b3b2454a79597f5f8b4637/html5/thumbnails/3.jpg)
What is Pex?
![Page 4: Pex](https://reader033.vdocuments.mx/reader033/viewer/2022061216/54b3b2454a79597f5f8b4637/html5/thumbnails/4.jpg)
Program Exploration
![Page 5: Pex](https://reader033.vdocuments.mx/reader033/viewer/2022061216/54b3b2454a79597f5f8b4637/html5/thumbnails/5.jpg)
Microsoft Research
Research in Software Engineering (RiSE)
![Page 6: Pex](https://reader033.vdocuments.mx/reader033/viewer/2022061216/54b3b2454a79597f5f8b4637/html5/thumbnails/6.jpg)
Nikolai Tillmann Peli de Halleux
Wolfram Schulte Nikolaj Bjørner
![Page 7: Pex](https://reader033.vdocuments.mx/reader033/viewer/2022061216/54b3b2454a79597f5f8b4637/html5/thumbnails/7.jpg)
Nikolai Tillmann Peli de Halleux
Wolfram Schulte Nikolaj Bjørner
![Page 8: Pex](https://reader033.vdocuments.mx/reader033/viewer/2022061216/54b3b2454a79597f5f8b4637/html5/thumbnails/8.jpg)
Pex generates inputs for your unit tests through automate exploratory testing
![Page 9: Pex](https://reader033.vdocuments.mx/reader033/viewer/2022061216/54b3b2454a79597f5f8b4637/html5/thumbnails/9.jpg)
Identify Test Inputs
• Pex doesn’t make wild guesses• Pex gains an understanding of your code• Static and dynamic analysis• Every input should increase code coverage
![Page 10: Pex](https://reader033.vdocuments.mx/reader033/viewer/2022061216/54b3b2454a79597f5f8b4637/html5/thumbnails/10.jpg)
Parameterised Unit Tests
[RowTest][Row(1, 2, 3)] [Row(-1, -2, -3)] public void TestForAddMethod(int a, int b, int expected){ int test = MyMethods.Add(a, b); Assert.AreEqual(test, expected);}
![Page 11: Pex](https://reader033.vdocuments.mx/reader033/viewer/2022061216/54b3b2454a79597f5f8b4637/html5/thumbnails/11.jpg)
Parameterised Unit Tests
[RowTest][Row(1, 2, 3)] [Row(-1, -2, -3)] public void TestForAddMethod(int a, int b, int expected){ int test = MyMethods.Add(a, b); Assert.AreEqual(test, expected);}
![Page 12: Pex](https://reader033.vdocuments.mx/reader033/viewer/2022061216/54b3b2454a79597f5f8b4637/html5/thumbnails/12.jpg)
Everything Ian said is still valid
![Page 13: Pex](https://reader033.vdocuments.mx/reader033/viewer/2022061216/54b3b2454a79597f5f8b4637/html5/thumbnails/13.jpg)
Exploratory Testing
• Learns more over time• More it knows, more it knows how to break it • Starts with simplest input
![Page 14: Pex](https://reader033.vdocuments.mx/reader033/viewer/2022061216/54b3b2454a79597f5f8b4637/html5/thumbnails/14.jpg)
HELLO WORLDDEMO
![Page 15: Pex](https://reader033.vdocuments.mx/reader033/viewer/2022061216/54b3b2454a79597f5f8b4637/html5/thumbnails/15.jpg)
Under the covers
![Page 16: Pex](https://reader033.vdocuments.mx/reader033/viewer/2022061216/54b3b2454a79597f5f8b4637/html5/thumbnails/16.jpg)
CLR Profiler API
ICorProfilerCallback2
![Page 17: Pex](https://reader033.vdocuments.mx/reader033/viewer/2022061216/54b3b2454a79597f5f8b4637/html5/thumbnails/17.jpg)
![Page 18: Pex](https://reader033.vdocuments.mx/reader033/viewer/2022061216/54b3b2454a79597f5f8b4637/html5/thumbnails/18.jpg)
Z3 Constraint Solver
![Page 19: Pex](https://reader033.vdocuments.mx/reader033/viewer/2022061216/54b3b2454a79597f5f8b4637/html5/thumbnails/19.jpg)
The Problem
![Page 20: Pex](https://reader033.vdocuments.mx/reader033/viewer/2022061216/54b3b2454a79597f5f8b4637/html5/thumbnails/20.jpg)
Some people aren’t unit testing
Ok... Most people
![Page 21: Pex](https://reader033.vdocuments.mx/reader033/viewer/2022061216/54b3b2454a79597f5f8b4637/html5/thumbnails/21.jpg)
Lots of people think they are writing tests but in reality they
aren’t
![Page 22: Pex](https://reader033.vdocuments.mx/reader033/viewer/2022061216/54b3b2454a79597f5f8b4637/html5/thumbnails/22.jpg)
[Test]public void Test1(){ Engine e = new Engine(); Customer c = e.GetCustomer(123); Order o = new Order(1, “Product X”) o.Customer = c; Assert.IsTrue(e.PlaceOrder(o));}
![Page 23: Pex](https://reader033.vdocuments.mx/reader033/viewer/2022061216/54b3b2454a79597f5f8b4637/html5/thumbnails/23.jpg)
Those who are, 100% code coverage is rare
Especially with Legacy Code
![Page 24: Pex](https://reader033.vdocuments.mx/reader033/viewer/2022061216/54b3b2454a79597f5f8b4637/html5/thumbnails/24.jpg)
Test Driven Development on complex code is difficult
![Page 25: Pex](https://reader033.vdocuments.mx/reader033/viewer/2022061216/54b3b2454a79597f5f8b4637/html5/thumbnails/25.jpg)
Encryption and Decryption algorithms
![Page 26: Pex](https://reader033.vdocuments.mx/reader033/viewer/2022061216/54b3b2454a79597f5f8b4637/html5/thumbnails/26.jpg)
Parsers and Compilers
![Page 27: Pex](https://reader033.vdocuments.mx/reader033/viewer/2022061216/54b3b2454a79597f5f8b4637/html5/thumbnails/27.jpg)
Decision Tables
![Page 28: Pex](https://reader033.vdocuments.mx/reader033/viewer/2022061216/54b3b2454a79597f5f8b4637/html5/thumbnails/28.jpg)
Aim of Pex is to solve these problems
![Page 29: Pex](https://reader033.vdocuments.mx/reader033/viewer/2022061216/54b3b2454a79597f5f8b4637/html5/thumbnails/29.jpg)
The Real World
![Page 30: Pex](https://reader033.vdocuments.mx/reader033/viewer/2022061216/54b3b2454a79597f5f8b4637/html5/thumbnails/30.jpg)
DECISION TABLEDEMO
![Page 31: Pex](https://reader033.vdocuments.mx/reader033/viewer/2022061216/54b3b2454a79597f5f8b4637/html5/thumbnails/31.jpg)
IP ADDRESS GENERATORDEMO
![Page 32: Pex](https://reader033.vdocuments.mx/reader033/viewer/2022061216/54b3b2454a79597f5f8b4637/html5/thumbnails/32.jpg)
![Page 33: Pex](https://reader033.vdocuments.mx/reader033/viewer/2022061216/54b3b2454a79597f5f8b4637/html5/thumbnails/33.jpg)
PEX EXTENSIONSDEMO
![Page 34: Pex](https://reader033.vdocuments.mx/reader033/viewer/2022061216/54b3b2454a79597f5f8b4637/html5/thumbnails/34.jpg)
The Future
![Page 35: Pex](https://reader033.vdocuments.mx/reader033/viewer/2022061216/54b3b2454a79597f5f8b4637/html5/thumbnails/35.jpg)
Pex has limitations
Remember – it’s still research
![Page 36: Pex](https://reader033.vdocuments.mx/reader033/viewer/2022061216/54b3b2454a79597f5f8b4637/html5/thumbnails/36.jpg)
Difficult to start using
Remember – it’s still research
![Page 37: Pex](https://reader033.vdocuments.mx/reader033/viewer/2022061216/54b3b2454a79597f5f8b4637/html5/thumbnails/37.jpg)
Not available under a commercial license
VS2008 == ResearchVS2010 == Same as VS2010 CTP
![Page 38: Pex](https://reader033.vdocuments.mx/reader033/viewer/2022061216/54b3b2454a79597f5f8b4637/html5/thumbnails/38.jpg)
However!
![Page 39: Pex](https://reader033.vdocuments.mx/reader033/viewer/2022061216/54b3b2454a79597f5f8b4637/html5/thumbnails/39.jpg)
Very good with algorithms and complex code
![Page 40: Pex](https://reader033.vdocuments.mx/reader033/viewer/2022061216/54b3b2454a79597f5f8b4637/html5/thumbnails/40.jpg)
Used internally to test core component at Microsoft
![Page 41: Pex](https://reader033.vdocuments.mx/reader033/viewer/2022061216/54b3b2454a79597f5f8b4637/html5/thumbnails/41.jpg)
Code Contracts help guide Pex
Spec# \ C# 4.0
![Page 42: Pex](https://reader033.vdocuments.mx/reader033/viewer/2022061216/54b3b2454a79597f5f8b4637/html5/thumbnails/42.jpg)
BDD and Pex
![Page 43: Pex](https://reader033.vdocuments.mx/reader033/viewer/2022061216/54b3b2454a79597f5f8b4637/html5/thumbnails/43.jpg)
In summary...
![Page 44: Pex](https://reader033.vdocuments.mx/reader033/viewer/2022061216/54b3b2454a79597f5f8b4637/html5/thumbnails/44.jpg)
Summary
• Pex is a project from Microsoft research• Available today for VS2008 and VS2010 • Aims to make unit testing more effective• BDD + Pex
![Page 45: Pex](https://reader033.vdocuments.mx/reader033/viewer/2022061216/54b3b2454a79597f5f8b4637/html5/thumbnails/45.jpg)
![Page 46: Pex](https://reader033.vdocuments.mx/reader033/viewer/2022061216/54b3b2454a79597f5f8b4637/html5/thumbnails/46.jpg)
![Page 48: Pex](https://reader033.vdocuments.mx/reader033/viewer/2022061216/54b3b2454a79597f5f8b4637/html5/thumbnails/48.jpg)
Resources
• http://Blog.BenHall.me.uk• http://research.microsoft.com/pex/• http://www.codeplex.com/pex• http://blog.dotnetwiki.org/ (Peli’s Blog)• http://blogs.msdn.com/nikolait• PDC Session -
http://channel9.msdn.com/pdc2008/TL51
![Page 49: Pex](https://reader033.vdocuments.mx/reader033/viewer/2022061216/54b3b2454a79597f5f8b4637/html5/thumbnails/49.jpg)
Flickr Images
• http://www.flickr.com/photos/djbrady/1460272108/• http://www.flickr.com/photos/yukonblizzard/2562986305/• http://www.flickr.com/photos/frielp/6829509/• http://www.flickr.com/photos/atomicjeep/274667176/• http://www.flickr.com/photos/wouterpostma/695850212/• http://www.flickr.com/photos/leon_homan/2856628778/• http://www.flickr.com/photos/sadsnaps/2741479621/