Wednesday, February 22, 2012

TFS 2010 - Microsoft.TeamTest.targets(14,5): Object reference not set to an instance of an object

While trying to build unit test projects, you might have seen this error intermittently
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\TeamTest\Microsoft.TeamTest.targets(14,5): error : Object reference not set to an instance of an object.

To fix this issue, you should look at the warnings which you get while building this project. Even though they are not errors, these warnings could be the cause of intermittent failure. So try to fix the warnings and this should resolve the issue.

If this does not work, another fix is described at http://social.msdn.microsoft.com/Forums/en-US/tfsbuild/thread/bb0a1752-f6ce-4001-8b45-5aa72f1909e3

These steps need to followed:
  • Open the build definition
  • Go to Process tab
  • Select Logging Verbosity as Detailed

Tuesday, February 7, 2012

MSTEST - How to get the ID of a test

Sometimes you will come across situations where you need to find the ID of a testcase.
A common scenario is if you see an errors like:
Error adding test case xxx to test run: There is no test with specified Id {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}.
The easiest way to find the ID of a testcase is to use either of these options:
Option 1
  • Run the desired test
  • Open the trx file in xml editor to view the ID of the test
 Option 2
  • Create a test list in the test list  editor
  • Add the desired test to the test list
  • Open the vsmdi file in xml editor to view the ID of the added test
 Option 3
  • Create an Ordered test
  • Add the desired test to the Ordered test
  • Open the Ordered test in xml editor to view the ID of the added test

 

Friday, January 6, 2012

Windows Azure - Access to the path 'ServiceDefinition.build.csdef' is denied.

If you receive this error:
Error 102 Unable to copy file "ServiceDefinition.csdef" to "ServiceDefinition.build.csdef". Access to the path 'ServiceDefinition.build.csdef' is denied. C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\Windows Azure Tools\1.4\Microsoft.WindowsAzure.targets

The problem is that the file 'ServiceDefinition.build.csdef' is read-only. You will be able to find this file in your cloud project (.ccproj) directory. If you remove the read-only setting, the error will disappear and build and publish commands will work properly.

Could not establish trust relationship for the SSL/TLS secure channel

This is a common problem in the testing world where you deploy a service on a HTTPS endpoint by using a self-signed certificate.
When you try to send a request to this service using HTTPWebRequest/WebClient, you see the error:
The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.
The solution to this problem is to ignore the trust by using the following code:

using System.Net;
using System.Net.Security;

           
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(delegate { return true; });

HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://www.mysite.com");

HttpWebResponse response = (HttpWebResponse)request.GetResponse();

Stream stream = response.GetResponseStream();

StreamReader sr = new StreamReader(stream);

string resp = sr.ReadToEnd();

Monday, December 5, 2011

MSTEST - UTA004: Illegal use of attribute on testmethod

Have you seem this error UTA004: Illegal use of attribute on testmethod. The TestMethodAttribute can be defined only inside a class marked with the TestClass attribute. while trying to run a mstest unit test.
The common scenario when this occurs is if there is a method with [TestMethod] attribute but the class in which it is defined does not have [TestClass] attribute.
However, even if you add the [TestClass] attribute and the error does not go away, the reason is that the class is not public.

Hence, make sure that the class is public and it has [TestClass] attribute.