Pex: How to obtain all Path Conditions (PC)?

294 views Asked by At

In possible to force Pex/Intellitest to look for any possible path condition? I need pex shows me those PC. In pexfonfun/visualstudio 2015, i can see only few PC. For example, infeasible PC aren't shown.

In the next example i get 3 PC:

1) i != 12 && i != 15;
2) i == 15;
3) i == 12;

public static int foo(int i){
   int a = 1;
   if(i == 12)
      a = 1;
   if(i == 15)
      a = 2;
   return a;
}

Why i dont get "i != 12 && i == 15"?

Thanks! :)

1

There are 1 answers

5
pvlakshm On BEST ANSWER

>> Why i dont get "i != 12 && i == 15"?

IntelliTest tries to generate a compact test suite with high coverage. For your example, notice that those 3 PC’s are enough to cover all blocks in your code. And therefore, IntelliTest decides that it can stop now. Here are some relevant sections from the IntelliTest Reference Manual that explain this further:

  1. To see how IntelliTest generates the data, please see here: https://www.visualstudio.com/en-us/docs/test/developer-testing/intellitest-manual/input-generation
  2. To see when IntelliTest decides to emit a test case, please see here: https://www.visualstudio.com/en-us/docs/test/developer-testing/intellitest-manual/test-generation

Please let me know how we can improve this manual as well.

OK, now having said that, you can get IntelliTest to generate all PCs as well (although it is not going to exercise any new code paths). Here is how to do that:

  1. Do a "Run IntelliTest" on your method.
  2. Select all the tests from the Exploration Results window, and hit the save button. Note that a new test project gets created.
  3. Locate the PUT in this test project – it will be the method with the PexMethod attribute.
  4. Condition IntelliTest to generate more PCs and emit tests by updating the PexMethod attribute as follows: [PexMethod(TestEmissionFilter = Microsoft.Pex.Framework.Settings.PexTestEmissionFilter.All)]
  5. Now do a "Run IntelliTest" again either on the PUT or on the product method, and you should see additional PCs (with "duplicate path" as the summary message). Experiment with EmissionFilter settings as you prefer.