简体   繁体   English

Pex:如何获取所有路径条件(PC)?

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

In possible to force Pex/Intellitest to look for any possible path condition? 是否有可能迫使Pex / Intellitest寻找任何可能的路径条件? I need pex shows me those PC. 我需要pex给我看那些PC。 In pexfonfun/visualstudio 2015, i can see only few PC. 在pexfonfun / visualstudio 2015中,我只能看到很少的PC。 For example, infeasible PC aren't shown. 例如,未显示不可行的PC。

In the next example i get 3 PC: 在下一个示例中,我得到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"? 为什么我没有得到“ i!= 12 && i == 15”?

Thanks! 谢谢! :) :)

>> Why i dont get "i != 12 && i == 15"? >>为什么我没有得到“ i!= 12 && i == 15”?

IntelliTest tries to generate a compact test suite with high coverage. IntelliTest尝试生成具有高覆盖率的紧凑型测试套件。 For your example, notice that those 3 PC's are enough to cover all blocks in your code. 对于您的示例,请注意那三台PC足以覆盖您代码中的所有块。 And therefore, IntelliTest decides that it can stop now. 因此,IntelliTest决定可以立即停止。 Here are some relevant sections from the IntelliTest Reference Manual that explain this further: 以下是《 IntelliTest参考手册》中的一些相关部分,进一步说明了这一点:

  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 要查看IntelliTest如何生成数据,请参见此处: https : //www.visualstudio.com/zh-cn/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 要查看IntelliTest何时决定发出测试用例,请参见此处: https : //www.visualstudio.com/zh-cn/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). 好的,话虽如此,您也可以使IntelliTest也生成所有PC(尽管它不会使用任何新的代码路径)。 Here is how to do that: 这样做的方法如下:

  1. Do a "Run IntelliTest" on your method. 对您的方法执行“运行IntelliTest”。
  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. 在此测试项目中找到PUT –这将是具有PexMethod属性的方法。
  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)] 通过更新PexMethod属性,使PexMethod条件状态,以生成更多PC并发出测试,如下所示: [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). 现在,在PUT或产品方法上再次执行“运行IntelliTest”,您应该看到其他PC(带有“重复路径”作为摘要消息)。 Experiment with EmissionFilter settings as you prefer. 尝试使用EmissionFilter设置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM