2015-05-04 150 views
2

我在Visual Studio 2013的单元测试中使用了Moq。我需要使用“vstest.console.exe”在命令行中运行测试用例。使用vstest.consol.exe运行Moq单元测试

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

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.

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

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

当试图individualy执行测试用例使用“/测试:“标签,我得到了更详细的错误信息:

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].

所以现在我知道原因是在我的te中使用Moq st案件。

我该如何解决这个问题?

回答

1

原来我用的是单元测试的dll文件的文件夹中的obj:

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

Visual Studio中放入bin文件夹中的所有相关的.dll文件,所以我改成:

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

问题解决了!

+0

如果您还有Visual Studio在同一个节点上,您可以运行一个长时间运行的测试,然后尝试使用进程资源管理器找出测试dll从哪个文件夹加载。然后使用Vstest.console.exe加载该dll的测试。你将不会再有同样的错误。 –

1

您需要确保这些依赖关系设置为“Copy Local = True”,vstest.console将能够在您的测试程序集旁边找到它们。