Top Banner
Ben Hall [email protected] Blog.BenHall.me.uk Pex The future of unit testing?
49

Pex

Jan 12, 2015

Download

Technology

Ben Hall

DDD7

http://blog.benhall.me.uk/2008/11/ddd7-slides-and-code-pex-future-of-unit.html
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Pex

Ben [email protected]

PexThe future of unit testing?

Page 2: Pex

Agenda

• What is Pex?• Problem Pex is trying to solve• Pex in the Real World• The future?

Page 3: Pex

What is Pex?

Page 4: Pex

Program Exploration

Page 5: Pex

Microsoft Research

Research in Software Engineering (RiSE)

Page 6: Pex

Nikolai Tillmann Peli de Halleux

Wolfram Schulte Nikolaj Bjørner

Page 7: Pex

Nikolai Tillmann Peli de Halleux

Wolfram Schulte Nikolaj Bjørner

Page 8: Pex

Pex generates inputs for your unit tests through automate exploratory testing

Page 9: Pex

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

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

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

Everything Ian said is still valid

Page 13: Pex

Exploratory Testing

• Learns more over time• More it knows, more it knows how to break it • Starts with simplest input

Page 14: Pex

HELLO WORLDDEMO

Page 15: Pex

Under the covers

Page 16: Pex

CLR Profiler API

ICorProfilerCallback2

Page 17: Pex
Page 18: Pex

Z3 Constraint Solver

Page 19: Pex

The Problem

Page 20: Pex

Some people aren’t unit testing

Ok... Most people

Page 21: Pex

Lots of people think they are writing tests but in reality they

aren’t

Page 22: Pex

[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

Those who are, 100% code coverage is rare

Especially with Legacy Code

Page 24: Pex

Test Driven Development on complex code is difficult

Page 25: Pex

Encryption and Decryption algorithms

Page 26: Pex

Parsers and Compilers

Page 27: Pex

Decision Tables

Page 28: Pex

Aim of Pex is to solve these problems

Page 29: Pex

The Real World

Page 30: Pex

DECISION TABLEDEMO

Page 31: Pex

IP ADDRESS GENERATORDEMO

Page 32: Pex
Page 33: Pex

PEX EXTENSIONSDEMO

Page 34: Pex

The Future

Page 35: Pex

Pex has limitations

Remember – it’s still research

Page 36: Pex

Difficult to start using

Remember – it’s still research

Page 37: Pex

Not available under a commercial license

VS2008 == ResearchVS2010 == Same as VS2010 CTP

Page 38: Pex

However!

Page 39: Pex

Very good with algorithms and complex code

Page 40: Pex

Used internally to test core component at Microsoft

Page 41: Pex

Code Contracts help guide Pex

Spec# \ C# 4.0

Page 42: Pex

BDD and Pex

Page 43: Pex

In summary...

Page 44: Pex

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
Page 46: Pex
Page 47: Pex

Ben [email protected]

Thank you

Page 48: Pex

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

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/