Home > TFS, TFS2012, Visual Studio > TFS2012: Run Data Driven Unit Tests in TFS Team Build

TFS2012: Run Data Driven Unit Tests in TFS Team Build


In a previous post, I explained how to run one test method twice using the data driven approach with Excel workbook as a datasource. The solution worked without issues when running using Visual Studio 2012. But I wasn’t able to run the unit tests using TFS Team build. I was getting the following error

The unit test adapter failed to connect to the data source or to read the data. For more information on troubleshooting this error, see “Troubleshooting Data-Driven Unit Tests” (http://go.microsoft.com/fwlink/?LinkId=62412) in the MSDN Library. Error details: ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified

image

The following is my setup:

3 VMS

Active Directory: Windows 2008 R2

TFS 2012 Express: Windows 2008 R2, SQL Server 2012 Express

Team Build Server: Windows 2008 R2, Team Build Controller and 1 Agent running as NT Authority\ Network Service

Troubleshooting Steps

Check if the Excel file is copied to the Out folder

In my case it was copied

image

Check if you have the proper drivers installed

 

In my case I had make sure that the ODBC driver for Excel xlsx files is installed. There are two versions of ODBC Datasource: 32bit and 64bit. To learn more about that topic checkout this KB http://support.microsoft.com/kb/942976

I opened both the 32bit and 64bit versions of the odbcad32.exe on the build machine and I noticed that the drivers were installed for the earlier version of Excel (xls) and not the 2007+ version (xlsx).

image

The reason it was working in Visual Studio (local machine) is I had Office 2010 installed on the machine that has Visual Studio.

I logged on as lab\administrator (domain admin rights) and then I Installed Office 2010

Now I opened the ODBCad32 and found out that the driver is installed and the DSN is added to the User DSN.

image

 

image

 

If I run the team build now, I will fail with the same error because the service is running as Network Service not lab\Administrator

Change the Run as account

Open the TFS Admin console from the build machine

Click on Build Configurations Node

Stop the Build Service

Click on Change in the Run the Service as groupbox

Select User a user account

WARNING: You MUST NOT use a domain admin for your run as service. I will change it later on in the article. The reason I am using a domain admin here is because I installed office using that account. The office installation adds the DNS names for at the user level which only accessible to the current user. I will show it to you working first then I will change the account.

Enter your username. If you keep the “User the same identity as Windows Service” checked, TFS will add this account to the Project Collection\Project Collection Build Service Accounts group. You can use a local machine admin account in the first box and a domain user with limited privileges in the Connect to TFS as box as I will show later on.

image

Click OK and Save.

Queue a team build

image

Replace Run as Service Account

Now I will replace the the run as Service Account as a local Administrator

Open the TFS admin console from the build machine

Build Configuration—>Service Property—>Stop the service

Click the change button

I am using a local admin account. If you template interact with other network computers you need to use a domain account.

image

Uncheck Use the same identity as windows Service

Click the Change button

Enter the account information. This account will be used for any interaction with TFS

image

Click and Start

Queue a new build

The build should fail with same error we had above.

image

I am getting this error because the installation of Office 2010 added the DNS name to the User DNS which means it is only available to the the current user. You can fix this issue by logging on as your new account and add the DNS to the User DNS tab.

Add Excel DNS to the Local DNS list

Log on as the new user (I am logging on as LocalAdmin). You can also run the Odbca32.exe as a different user if you don’t want of log off and on.

Open “C:\Windows\SysWOW64\odbcad32.exe”

In the User DNS

Click Add

image

Select Microsoft Excel Driver (the one that contains xlsx)

Click finish

Name it Excel Files

Click OK

Run the build again and it should pass

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: