Generate unit tests and run them with CI (Continuous integration) using Pex and MS Team Build 2010

[tweetmeme source=”mradwan06” only_single=false]
Continuous Integration + Microsoft Pex = Continuous Exploration

By exploring our code with Microsoft Pex in our continuous integration, we will leverage the full power of automated test generation.

  • First let’s deifne what is the Pex in nutshell ?

Pex is a white box testing framework that do the following:

  1. Generate parameterize unit test if it is not exist
  2. Run Pex Exploration on  parameterize unit test
  3. Generate unit tests with inputs depend on 2 things
    1. The code of the method under the test
    2. The precondition of the test data and parameters in the  parameterize unit test  (PexAssume)
  4. Identify if the generated unit tests will success or fail when they run?
So I can integrate the Pex in the CI (Continuous Integration) as the following
The pex will be used for the Domain and the DAL layer, I will not use Pex in the Controller or the Presentation layer (MVC)
First scenario :
  1. The developer using Pex in his/her day to day development tasks since he/she is working on the Domain or the DAL layer
  2. The developer start create the parameterize unit test manual and put any precondition as needed (PexAssume, ExpectException, etc.. )
  3. The developer run Pex Exploration on his/her manual parameterize unit test and see if there is any method generated will fail so he/she start adjust the parameterize unit test by adding  PexAssume, ExpectException and so on until all generated test methods become green which indicate that they will pass if they run
  4. The developer check-in his code (code under test and the manual parameterize unit test) in the source control
  5. The build start and run Pex Explortion against the manual  parameterize unit test and generate the unite tests and see if they has any unit test that fail so the build will fail
[sourcecode language=”xml”]
pex.exe MyApplication.Tests.dll /nor /ftf

Second scenario :
  1. The developer didn’t use Pex at all, the developer may use Pex for personal check only before check-in his code, the parameterize unit test will not checked-in  in the source control
  2. The developer start develop on the application
  3. The developer check-in his code in the source control
  4. The build start and run Pex to generate  parameterize unit test
  5. The build run Pex Explortion against the generated parameterize unit test and generate the unite tests and see if they has any unit test that fail so the build will fail
[sourcecode language=”xml”]
pex.exe MyApplication.dll /nor /ftf /erm:wizard

All you need to do to integrate Pex with MS Team Build 2010 just invoke the process of the CMD and run Pex from Command line and give it the appropriated parameters

Share This: