0

I have this strange problem. When I use the OpenCover from Visual Studio all tests pass and everything seems fine.

Image from Visual Studio here: https://i.stack.imgur.com/awmWy.png

But when I want to automate the tests using the OpenCover.Console.exe than some tests fail. I have noticed that the 2 failing tests read from config file.

Either the test or the code that is tested reads from config file using ConfigurationManager.AppSettings["someConfigValue"]. I have the same values in the main project and the test project appsettings.

The two failing tests when executing from console image here: https://i.stack.imgur.com/a77Tt.png

In addition I provide the command used for OpenCover.Console.exe.

"OpenCover.Console.exe" -register -target:"C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\MSTest.exe" -targetargs:"/noisolation /testcontainer:\"E:\TEAM\TestProject.Tests\bin\Debug\TestProject.Tests.dll" /resultsfile:TestResults.trx" -mergebyhash -output:CodeCoverage.xml

UPDATE [04 September 2015]

Since I did not find any particular solution, I came up with a workaround. Practically I have taken as granted that configuration file and all its data does not belong to unit tests, but to integration tests.

So in my code I do not use ConfigurationManager.AppSettings["someConfigValue"] any more. What I did is created a ConfigurationService and in the IConfigurationService I have all the methods I need for getting the values from the config file.

Having this injected in the BL of the solution, I use Mocks for unit testing purposes.

Igor Dimchevski
  • 412
  • 3
  • 13
  • Is the Current Working Directory when running from the console the same as when running from Visual Studio? – Roy T. Sep 02 '15 at 08:15
  • I suppose no, but will accept your suggestion and try it. – Igor Dimchevski Sep 02 '15 at 08:18
  • Nope, still no good. Visual Studio uses ***-target:"C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe"*** – Igor Dimchevski Sep 02 '15 at 10:11
  • try `-targetdir:"E:\TEAM\TestProject.Tests\bin\Debug"` this should cause OpenCover to set it's `CurrentDirectory` to that location; you could then try removing the path from the `/testcontainer` argument passed to mstest (vstest.console.exe) – Shaun Wilde Sep 02 '15 at 21:27
  • Thank you @ShaunWilde, I will try your suggestion. Even though I ended up with another workaround. – Igor Dimchevski Sep 03 '15 at 21:05
  • please update your question or even answer you your own question with your workaround as others may find it useful. – Shaun Wilde Sep 04 '15 at 09:24
  • @ShaunWilde I just tried your suggestion and the same thing happens again. I will write down my workaround as an UPDATE to the question – Igor Dimchevski Sep 04 '15 at 13:41

0 Answers0