【问题标题】:Moles creation does not create all objects痣的创建不会创建所有对象
【发布时间】:2012-01-05 18:55:00
【问题描述】:

在尝试为某些单元测试创​​建摩尔时,我注意到某些函数没有被“摩尔”。一些函数出现在 xxx.moles.xml 文件中,而另一些则没有。

为解决此问题,我尝试重新安装“Pex and Moles”、删除 MolesAssembly 文件夹中的文件、重新启动计算机等。

最后,我只是打开了一个控制台窗口并从命令提示符运行了 moles.exe 命令。

"c:\program files\microsoft moles\bin\moles.exe" assembly.dll /op:"MolesAssemblies" /msbuild:"c:\windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe"

第一次运行时,我收到一条消息:

鼹鼠:信息:编译:程序集元数据哈希不变, 跳过代码生成。

删除 MolesAssemblies 文件夹中的痣后,我再次运行 moles.exe 命令,我的所有函数现在都出现在 xxx.moles.dll 和 xxx.moles.xml 文件中。

有谁知道为什么在 Visual Studio 2010 中构建时痣生成不起作用,但在命令提示符下却完美运行?

【问题讨论】:

    标签: moles


    【解决方案1】:

    我发现了问题...我之前修改了 .moles 文件,只添加了某些类。我只需要添加更多的“TypeName”并包含类/函数。

    使用 moles.exe 命令“工作”的原因是因为我没有使用 .moles 文件(我只是引用了程序集)。我更改了 moles.exe 的参数以包含 .moles 文件和程序集,结果与 Visual Studio 生成的输出相同。当我注意到代码的其他部分出现问题时,我意识到 .moles 文件不正确。

    我有这样的事情......

    <Moles xmlns="http://schemas.microsoft.com/moles/2010/" >
      <Assembly Name="Assembly.name" />
        <StubGeneration>
            <Types>
                <Clear />
                <Add FullName="Fullname_1_0" />
            </Types>
        </StubGeneration>
        <MoleGeneration>
            <Types>
                <Clear />
                <Add FullName ="Fullname_1_0" />
            </Types>
        </MoleGeneration> 
    </Moles>
    

    我需要第二个“添加”

    <Moles xmlns="http://schemas.microsoft.com/moles/2010/" >
      <Assembly Name="Assembly.name" />
        <StubGeneration>
            <Types>
                <Clear />
                <Add FullName="Fullname_1_0" />
            </Types>
        </StubGeneration>
        <MoleGeneration>
            <Types>
                <Clear />
                <Add FullName ="Fullname_1_0" />
                <Add TypeName="AdditionalClass"/>
            </Types>
        </MoleGeneration> 
    </Moles>
    

    【讨论】:

      【解决方案2】:

      一定要在修改了一个被合并的程序集之后重新构建测试项目。对测试项目使用“clean”操作也可以解决此问题。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2019-01-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多