MSTest.exe not finding app.config

2019-03-10 04:05发布

I'm currently trying to run MSTest.exe from NCover, but I believe the question could apply generally to running MSTest.exe from the command line.

If I have the "/noisolation" argument, then MSTest.exe appears to find and use the app.config as expected. Without it, NCover doesn't capture any coverage information. From my research so far, it seems NCover needs /noisolation. So the question is how to get my *.config files to work when that argument is passed.

My NCover settings are:

Application to Profile
C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\MSTest.exe

Working Folder
C:\Documents and Settings\MyProfile\My Documents\Visual Studio 2008\Projects\XYZ\XYZ.CoreTest\bin\Debug

Application arguments
/noisolation /testcontainer:"C:\Documents and Settings\MyProfile\My Documents\Visual Studio 2008\Projects\XYZ\XYZ.CoreTest\bin\Debug\XYZ.CoreTest.dll"



Update: I added a trace showing that my config is (not surprisingly) trying to read from "C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\MSTest.exe.Config".

Update 2: If at all possible, I don't want to edit MSTest.exe.Config. That just isn't terribly portable.

9条回答
Summer. ? 凉城
2楼-- · 2019-03-10 04:19

I've never before used NoIsolation, but if I am understanding it correctly, it literally runs all of your test code in the MSTest class. That being so, it does and should read the App config for MSTest. If you insist on using noisolation, I'm thinking you would have to merge your App.config into MSTest.exe.config. Of course, that is a hack.

It would probably be better to avoid the noisolation altogether. If it is due to an error, fix the error if possible. Work around the error if reorganizing (major refactoring) your app is not possible. I'm not sure there is an elegant alternative.

I found "I think we need to find the root cause of this issue in order to avoid the noisolation switch. You might need to modify your applicaton. Is it possible to create a simple solution that repro the same issue?" at this URL.

查看更多
虎瘦雄心在
3楼-- · 2019-03-10 04:21

To clear up the confusion: not using /noisolation = if it finds a SameNameAsYourDll.dll.config file, it'll be deployed with the test dll automatically, and will be used for the app config for the app domain that runs the tests in that assembly

using /noisolation = All the isolation we do between tests, you, the host process, and everything else is out the window. We may still do some isolation, but you don't get the added benefit of the app domain being unique to your test dll. Thus, you dll's config won't help.

查看更多
Melony?
4楼-- · 2019-03-10 04:23

There's a technique where you can combine the contents of config files it's detailed here. You could add a fixed file inlcude line to MSTest.exe.Config, and then copy your app's app.config to that fixed file location. It's ugly, but more portable than hacking MSTest.exe.Config for every different eventuality.

查看更多
做自己的国王
5楼-- · 2019-03-10 04:24

At http://docs.ncover.com/ref/2-0/whats-new-in-ncover-2-0/release-notes-for-ncover-2-1-0/ under NCover Fixes:

Running coverage on MSTest no longer requires the "/noisolation" flag. NCover correctly gathers coverage

If this is indeed fixed, then upgrade NCover to 2.1.0. Perhaps that will work.

查看更多
We Are One
6楼-- · 2019-03-10 04:24

I had the same problem in Jenkins builds with MSTestRunner Plugin. Checking Omit NoIsolation from configuration page solved the problem.

查看更多
爷的心禁止访问
7楼-- · 2019-03-10 04:24

Try changing its name from app.config to projectname.extension.**config**

For example, if you have a unit test project named proj1 and you use its dll, rename app.config to proj1.dll.config

This worked for me.

查看更多
登录 后发表回答