我尝试使用Pex来探索以下方法:
public float MultiplyFloat(float a, float j)
{
if (a * a == 2)
{
if (j == 123)
{
a = 2;
}
}
else
a = 3;
return 3;
}
我知道Z3是一个线性算术求解器,不支持浮点,但Visual Studio 2010插件中的Pex向导建议我使用“Moles Type”,我使用这个建议和Pex Wizard创建:
1)Microsoft.Pex.Framework.moles文件
<Moles xmlns="http://schemas.microsoft.com/moles/2010/">
<Assembly Name="Microsoft.Pex.Framework" />
</Moles>
2)准备好的课程:__TestabilityHelperPreparation
using System;
using Microsoft.Pex.Framework;
using Microsoft.Pex.Engine.Symbols.Moles;
using Microsoft.Pex.Engine.Symbols;
namespace Microsoft.Pex.Engine.Symbols.Preparations
{
/// <summary>Contains a method to prepare the type __TestabilityHelper</summary>
public static partial class __TestabilityHelperPreparation
{
/// <summary>Prepares the environment (and the moles) before executing any method of the prepared type __TestabilityHelper</summary>
[PexPreparationMethod(typeof(__TestabilityHelper))]
public static void Prepare()
{
M__TestabilityHelper.BehaveAsCurrent();
// TODO: use Moles to replace API that call into the environment
}
}
}
但不能使用以下错误进行编译:
C:\Program Files (x86)\Microsoft\Contracts\MsBuild\v4.0\Microsoft.CodeContracts.targets(274,5): error MSB3073: uscita dal comando ""C:\Program Files (x86)\Microsoft SDKs\Windows\v8.0A\Bin\sn.exe" /R "o\Microsoft.Pex.Framework.Moles.dll" "m.g.snk"" con codice 9009. [D:\BenchMarkTesterToolLib.Tests02\obj\Debug\Moles\mpf\m.g.csproj]
Moles compilation FAILED - 58,028916314783s
C:\Program Files\Microsoft Moles\bin\Microsoft.Moles.targets(79,5): error MSB3073: uscita dal comando ""C:\Program Files\Microsoft Moles\bin\moles.exe" @D:\BenchMarkTesterToolLib.Tests02\obj\Debug\Moles\moles.args" con codice -1002.
那么,我是一个错误还是Pex建议我一个错误的解决方案?
感谢。
答案 0 :(得分:1)
问题实际上是代码合同,它运行的是sn
的错误版本。这已在最新版本的代码合同中修复。因此,请尝试更新代码合同,然后重试。