CovrageInfo.CreateFromFile发出错误

时间:2013-03-04 13:03:10

标签: vb.net unit-testing code-coverage

我已复制示例中的代码以从Here收集代码覆盖率的结果,但我的代码是vb.net

这是我的代码

Imports Microsoft.VisualStudio.Coverage.Analysis


Module Module1

    Sub Main()
        Using info As CoverageInfo = CoverageInfo.CreateFromFile("C:MyFile\data.coverage")

            Dim lines As New List(Of BlockLineRange)()

            For Each [module] As ICoverageModule In info.Modules

                Dim coverageBuffer As Byte() = [module].GetCoverageBuffer(Nothing)
                Using reader As ISymbolReader = [module].Symbols.CreateReader()

                    Dim methodId As UInteger = 0
                    Dim MethodName As String = ""
                    Dim undecoratedMethodName As String = ""
                    Dim ClassName As String = ""
                    Dim NameSpaceName As String = ""

                    lines.Clear()

                    While reader.GetNextMethod(methodId, MethodName, undecoratedMethodName, ClassName, NameSpaceName, lines)

                        Dim stats As CoverageStatistics = CoverageInfo.GetMethodStatistics(coverageBuffer, lines)
                        Console.WriteLine("Method {0}{1}{2}{3}{4} has:" & NameSpaceName & ClassName & undecoratedMethodName)

                        Console.WriteLine(" blocks covered are {0}", stats.BlocksCovered)
                    End While
                End Using
            Next

        End Using
    End Sub

End Module

当我在CreateFromFile的行上运行时,我得到ImageNotFoundException

Image File "C:\SomeAddress\MyServer\UnitTest.dll" could not be found 

我已根据说明添加了复制的项目所需的dll以及其他2作为参考。

1 个答案:

答案 0 :(得分:0)

还有另一个风滚草的时刻......

基本上问题是包含我的coverage文件的文件夹也必须包含在该组合中使用的所有dll,以便运行测试以创建该对象。

希望如果你曾经偶然发现这个问题,这会对你有所帮助:)