找到你要的答案

Q:Using vstest.consol.exe to run Moq unit tests

Q:使用vstest.consol.exe跑起订量的单元测试

I have used Moq in my unit tests in Visual Studio 2013. I need to run the test cases in Command-line using "vstest.console.exe".

When trying to do so, I get this error:

Error: An exception occurred while invoking executor 'executor://mstestadapter/v1': Could not load file or assembly 'Codex.Repository, verion=1.0.0.0, Clture-neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.

This is the command I use to run tests:

vstest.console.exe "C:.../Codex.repository.unittests.dll" /UseVsixVersion /Framework:framework45

When trying to execute the test cases individualy using "/Tests:" tag, I got a more detailed error message:

Could not load file or assembly 'Moq, Version=4.2.1502.911, Culture-neutral, PublicKeyToken=69f4...' or one of its dependencies. The system cannot fild the file specified.WRN: Assembly binding logging is turned OFF. To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1. Note: there is some performance penalty associated with assembly bind failure logging. To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].

So now I know the reason is using Moq in my test cases.

How can I solve this problem?

我在我的单元测试在Visual Studio 2013中使用的最小起订量。我需要运行的测试用例中的命令行使用“VSTest。控制台.exe”。

当试图这样做,我得到这个错误:

错误:在调用执行的执行发生异常:/ / mstestadapter / V1:未能加载文件或程序集“Codex.Repository,版本= 1.0.0.0,文化中性、PublicKeyToken = null”或它的一个依赖。系统找不到指定的文件。

这是我用来运行测试的命令:

vstest.console.exe "C:.../Codex.repository.unittests.dll" /UseVsixVersion /Framework:framework45

当试图执行测试用例分别使用“/测试”的标签,我有了一个更详细的错误信息:

未能加载文件或程序集“Moq版= 4.2.1502.911,文化中性、PublicKeyToken = 69f4…”或它的一个依赖。系统无法现场文件specified.wrn:装配约束测井是关闭的。为了使大会绑定失败记录,设置注册表值[ HKLM \软件\微软\融合!enablelog ](DWORD)1。注意:与装配绑定失败日志相关的一些性能损失。要关闭此功能,删除注册表值[ HKLM \软件\微软\融合!enablelog ]。

所以现在我知道的原因是使用最小起订量在我的测试用例。

我怎样才能解决这个问题?

answer1: 回答1:

You need to make sure these dependencies are set to "Copy Local = True" that way vstest.console will be able to find them alongside your test assembly.

你需要确保这些依赖项都设置为“复制本地= true”这样vstest.console就能找到他们在您的测试组件。

answer2: 回答2:

Originally I was using the unit test dll file in the obj folder:

c:\>vstest.console.exe "..\obj\release\unittests.dll"

Visual Studio puts all dependent .dll files in the bin folder so I changed to:

c:\>vstest.console.exe "..\bin\release\unittests.dll"

Problem solved!

我最初是在目标文件夹中使用单元测试的DLL文件:

c:\>vstest.console.exe "..\obj\release\unittests.dll"

Visual Studio将所有依赖。dll文件的bin文件夹中所以我改变:

c:\>vstest.console.exe "..\bin\release\unittests.dll"

问题解决了!

c#  visual-studio  unit-testing  moq  vstest