49

I've encountered an error when running unit tests. If I Debug the unit tests vstest.executionengine.x86.exe runs, then closes when the tests pass.

If I just run the tests (Even if the test is as simple as just creating a new list, with no asserts) vstest.executionengine.x86.exe doesn't close and stays running in task manager.

This is causing an issue for me when it comes to writing more complicated tests that include removing files / cleaning up sqllite databases.

Any help would be appreciated.

EDIT :

Steps to reproduce :

  • Create New Unit Test Project
  • Debug Unit Tests - vstest.executionengine.x86 opens and closes, test passes.
  • Run Unit Tests - vstest.executionengine.x86 opens and stays open
4
  • 1
    MSDN bug report: connect.microsoft.com/VisualStudio/feedback/details/771994/… (please vote!)
    – skolima
    Jan 8, 2013 at 10:17
  • 4
    My favorite workaround is Run the tests through ReSharper's test runner.
    – Ryan Gates
    Mar 15, 2013 at 18:53
  • I uninstalled resharper on vs 2012 thinking that "it" was the problem, but not so ughhh Apr 22, 2013 at 21:01
  • 1
    @RyanGates: That is not actually the best workaround when you are trying to run tests in 64 bit mode. Sometimes ReSharper fails at that. Apr 20, 2017 at 14:33

6 Answers 6

57

This is by design.

The vstest.executionengine.exe is restarted only when we detect a change in the configuration between two consecutive test runs. This helps ensure we aren't taking a perf hit on process restarts unnecessarily.

Product Update With VS2013 we have a new menu item under Test -> Test Settings called "Keep Test Execution Engine Running". You can uncheck this to opt out of the default behavior.

8
  • 69
    It also locks the DLLs being tested which results in not being able to build after running the unit tests. Any theoretical performance gains from not restarting the test runner are lost if the user has to manually kill the test runner process in order to build after changing code. Jan 7, 2013 at 23:28
  • 12
    I can confirm that this is an issue. I have to keep manually closing vstest.executionengine using task manager otherwise the build fails because it cannot write the output file.
    – Dave
    Feb 13, 2013 at 11:58
  • 1
    @Dave the question posted here is wrt VS2012 client and not build. If you provide details on the tfs/vs versions and what type of tests you are running I could try to help or it may be better to post a question about that to avoid hijacking this thread.
    – allen
    Feb 13, 2013 at 13:38
  • 8
    It definitely locks the dll and pdb. I have to Kill the vstest.executionengine.exe in order to built my solution, but cannot build my solution because vstest.executionengine.exe is locking the dll and pdb from being deleted. VS 2012 64 bit / windows 7 . I kill vstest.executionengine.exe and I can delete the files and then build. Apr 22, 2013 at 21:11
  • 4
    I can confirm the DLL locking as well. Build fails and a quick check with Process Explorer (Find Handle) shows the culprit vstest.executionengine.x86.exe.
    – Erwin Alva
    May 16, 2014 at 20:53
41

I worked around this by using the following as a pre-build event on the affected test projects:

for 64-bit:

taskkill /F /IM vstest.executionengine.exe /FI "MEMUSAGE gt 1"

or for 32-bit:

taskkill /F /IM vstest.executionengine.x86.exe /FI "MEMUSAGE gt 1"

This silently kills the execution engine before building the test project. The /FI "MEMUSAGE gt 1" stops the command (and therefore the build) from failing if the execution engine isn't running.

2
  • 1
    This is awesome stuff! Works! I had to kill my process manually every time.
    – Krumelur
    Dec 12, 2013 at 19:11
  • 1
    After trying several less invasive options, I ended with your solution. taskkill /F /IM vstest.discoveryengine.exe /FI "MEMUSAGE gt 1" in my case.
    – Fantastory
    Aug 18, 2015 at 13:56
5

For what its worth, I ran into this same situation and it turned out that I had a test that did not properly clean up all of its resources. In my specific case there was a background thread with a network connection open that did not get closed before the test exited. Not sure why exiting the test did not close this for me, but when i fixed my code to properly dispose of all the resources I opened, everything worked as expected. I did not have to add any hacks to kill the vstest.executionengine.exe, nor did I have to opt out of Test -> Test Settings -> Keep Test Execution Engine Running

2

I had this issue when running test using Resharper's test runner which doesn't seem to respect the Test-->Test Settings-->Keep Test Execution Engine Running setting. In my case it was causing the build to fail with the following error:

warning MSB3026: Could not copy "...\SQLite.Interop.dll" to "bin\Debug\x86\SQLite.Interop.dll". Beginning retry 10 in 1000ms. The process cannot access the file 'bin\Debug\x86\SQLite.Interop.dll' because it is being used by another process.

Adding a pre-build event to the test project as @HappyCat suggested worked for me. I also needed to wrap it in an if statement to prevent it from running on the build server and interfering with other jobs.

if $(ConfigurationName) == Debug (
    echo "attempting to kill vstest to prevent access denied on sqlite.interop.dll"
    taskkill /F /IM vstest.executionengine.x86.exe /FI "MEMUSAGE gt 1"
)
1

I know this is old but I thought I'd throw in something I just discovered.

A test I was running had some objects in it that implemented IDisposable, so the code analysis told me so should my test class. It took a while to realize it, but when this.Dispose(); was getting called on the implementation of that interface when I put it on my test class, it was actually throwing a StackOverflow exception. So I just yanked the interface and let CA continue to whine.

I did not need to toggle 'Keep Test Execution Engine Running'.

0

The easiest approach is to go to windows task manager. Look out for vstest.executionengine.exe process running in the background. Kill that process and it should work fine now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.