2
votes

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?

2

2 Answers

2
votes

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!

1
votes

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.