Unit testing Web Services - Code coverage failing
Hi All,
I'm having an issue with unit testing webservices from the command-line (works fine from within Visual Studio).
I have a testrunconfig file that has codecoverage enabled for this test web service (the default hello world). The method I am testing is:
[WebMethod]
publicstring HelloWorld()
{
return"Hello World";
}
The code I am using for the testing (basically the auto generated code modified to actually test correctly) is:
[TestMethod(),
AspNetDevelopmentServer("WebServicesTestServer","MyWebService")]
publicvoid HelloWorldTest()
{
Directorytarget =newDirectory();
if (WebServiceHelper.TryUrlRedirection(target,this.TestContext,"WebServicesTestServer")
==false)
{
Assert.Fail("Unableto do WebService redirection!"
);
}
stringexpected ="Hello World";
string
actual;
actual = target.HelloWorld();
Assert.AreEqual(expected,
actual);
}
This works perfectly fine in visual studio but when I build and deploy the webservice and then run mstest from the commandline with instrumentation enabled and passing in the same testrunconfig that is used by VisualStudio I get the following error:
=============================
Cannot initialize post instrumentation for the ASP.NET project 'c:\builds\MyWebService'.
Exception was thrown: System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.VisualStudio.Enterprise.Common.AspNetHelper.SetupPaths()
at Microsoft.VisualStudio.Enterprise.Common.AspNetHelper.SetupListener()
at Microsoft.VisualStudio.Enterprise.Common.AspNetHelper.SetupInstrument(Type type)
at Microsoft.VisualStudio.TestTools.CodeCoverage.CoveragePlugIn.InitAspNetInstrumentation(TestRun testRun).
The code coverage data for this project may be incomplete.
=============================
Anybody have any idea what is going on here?
Hello Brian,
Is this the released version of Visual Studio 2005?
Also, are you running MSTest.exe on those tests on the same machine as the one you are running the VS IDE and with the same test run configuration?
Could you also check what values do you have under the following registry key:
"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\8.0\InstalledProducts\Instrumentation"
There should be "Location" and "VSInstr" and both should not be empty.
Thank you,
Boris
Hi Boris,
This is the final version of Visual Studio 2005 (Actually it's Visual Studio 2005 Team Developer).
The tests are being run on a different machine to where the code is tested but this machine also has Visual Studio 2005 on it - the same test run config is being used and passed into mstest.exe.
The following values are under the registry key :
Location - "c:\Program Files\Microsoft Visual Studio 8\Team Tools\Performance Tools\"
VSInstr - "VSInstr.exe"
Oh, and testing and code coverage works fine on other types of apps (e.g. winforms, dll's, console apps, etc - just not on ASP.NET web services)
B
Hi Brian,
According to the stack trace you provided, the error happens during initialization of the ASP.NET code coverage instrumentation. It is not affecting other types of code coverage collection.
I have those questions for you:
1. On the machine, where MSTest.exe is failing, does VS IDE execute those test normally with coverage data collected?
2. Do you run MSTest.exe as a restricted account? If yes, try running it as an Administrator to see whether this solves the problem.
3. Do you run MSTest.exe normally - from its installed location on the local machine?
Thank you,
Boris