15

I have been using nunit with visual studio 2010 on a windows 7 64-bit pc.

I am able to open the nunit gui and run my unit tests. If I then change one of the unit tests and try to rebuild, I am getting a file locking error as follows -

Error 1 Unable to copy file "obj\Debug\myProject.Tests.dll" to "bin\Debug\myProject.Tests.dll". The process cannot access the file 'bin\Debug\myProject.Tests.dll' because it is being used by another process. myProject.Tests

I have used process explorer to verify that it is the nunit-agent.exe that is locking the dll.

I have noticed via tools > test assemblies that the nunit.exe is running under clr version Net 2.0 and nunit-agent.exe is running under clr version Net 4.0. could that have something to do with the problem? If so, how can I fix it? If not, does anyone have any idea what else may be going on?

Thanks for any thoughts.

kmatyaszek
  • 19,016
  • 9
  • 60
  • 65
czuroski
  • 4,316
  • 9
  • 50
  • 86
  • possible duplicate of [NUnit: "The process cannot access the file ... because it is being used by another process."](http://stackoverflow.com/questions/935244/nunit-the-process-cannot-access-the-file-because-it-is-being-used-by-anoth) – Kos Jan 22 '12 at 14:41

4 Answers4

18

I think this has to do with the placement of my test project. Initially, I was putting the nunit test project in a seperate directory from my dll files. I was thinking that I would keep all of my test projects in one centralized location.

I them moved my test project into the same location as my test dlls under my visual studio projects. After that, it seems to be working correctly.

I think this has to do the shadow copy. I read in the nunit group on google that the .net framework will only shadow copy assemblies in the application base or it's subdirectories.

This led me to try creating the nunit test project within my application base and that seemed to work.

Hope that makes sense.

Thanks

czuroski
  • 4,316
  • 9
  • 50
  • 86
8

I also faced the exact issue, however czuroski's answer did not work for me (although I think that we are in effect talking about the same thing).

What did work for me was to ensure that in NUnit I set the Project Path and Project Base were pointing to the same root application folder under Project -> Edit. I re-saved my existing Nunit project to the same directory as my VS sln file.

Wayne Werner
  • 49,299
  • 29
  • 200
  • 290
Ahmad
  • 22,657
  • 9
  • 52
  • 84
  • Thanks so much. I didn't want to bring the NUnit project into the project directory to avoid messing up the version control repo. Updating the `Project Base` to point to the solution directory helped! – Kos Jan 22 '12 at 14:38
2

Another thing to check is to make sure that Shadow Copy is enabled in Nunit -> Tools -> Settings -> TestLoader -> Advanced -> Enable Shadow Copy

Sam Shiles
  • 10,529
  • 9
  • 60
  • 72
0

try this, Tools > Settings > Test Loader > Assembly Isolation > Default Process Model > Run tests in a separate process per Assembly.

daniel
  • 1
  • 1
    I would recommend that you add some explanatory text to your answer, or you risk having it deleted as 'low quality' (even though it may be a correct answer)! – Adrian Mole Oct 12 '19 at 05:30