Archives de la catégorie PEX

PEX – Program EXploration with a simple sample – a Microsoft framework to have a complete test coverage

Pex is a Microsoft framework that explore all execution branch in a method and create all the unit test unit to have a complete test coverage.

Create a library class we will use to create unit test with pex :

create a method in BizService with a simple algorithm that shows how Pex Framework create unit test for you in order to have a complete test coverage that test all execution Branches:

Now run Pex (to download it http://research.microsoft.com/en-us/projects/pex/downloads.aspx) on right clicking on the method and select run Pex:

you obtain in Pex exploration result 4 test, using a null value, an empty value and the value you want to test. Pex run 4 times the method in order to discover all execution branch:

as you can see a failure test appears because we throw an exception : it is an expected result so we will allow this one by right clicking on this test and we will allow it:

Pex ask us to create a test project : accept

we can see the new test project in solution explorer:

 

in MyBizServiceTest.cs file, Pex create a unit test:

Pex create those  tests in MyBizServiceTest.runDifferentExecutionBranch.g.cs (solution explorer):

at the first test, we can see the expected exception NullReferenceException

re-run test by clicking Run buttong in Pex exploration Results and now all are passed:

we have also a panel Pex explorer where we can see unit test name

Conclusion : Pex create all test for us in order to test all execution path

Publicités

, , , , ,

Poster un commentaire

Microsoft System Center 2012

All System Center 2012 products, Service Manager, App-Controller, Orchestrator, Virtual Machine Manager, Configuration Manager, Data Protection Manager, Operation Manager -Boutougha Hassan

Microsoft Windows Server 2012

IT - Windows server 2012 - Hassan Boutougha

Microsoft Hyper-V

IT - Hyper-V - Hassan Boutougha

Microsoft SQL Server 2012

IT - SQL Server 2012 - Hassan Boutougha