Tuesday, 18 April 2006

Browse WebApp Here

It's all Dominick's fault. He pointed me at this blog entry. After I'd downloaded this I realised it wasn't what I thought, very cool, but not what I was expecting.

I was expecting this to be a 'Run Cassini and browse to the default page' web extension and as it wasn't I decided to write my own.

The code is available here. The zip comes with a .reg file that you need to edit to include the fully qualified path the the executable, the readme.txt shows and example. After it is installed you should be able to right click on a folder and see this .
Select 'Browse Web Application Here' and Cassini should start and a browser page should be opened connecting to the web site. You will need Visual Studio 2005 installed (Cassini is shipped with VS 2005).

Enjoy, and as always feedback is welcome.

Posted by kevin at 2:32 PM in Net

Sunday, 16 April 2006

Visual Studio Custom Checkin Policy Template

I've been spending some time writing custom checkin policies for VSTS, so many in fact that I decided to write a Visual Studio template. This weas very straightforward except for the fact that I when you edit the .vstemplate file you also need to remember to edit the .csproj file (if any file names are affected).

The template is here. Copy this file to your "Visual Studio user project templates location" (you can find this under Tools..Options..Projects and Solutions") and you should be good to go.

Any feedback gratefully received.

Posted by kevin at 5:35 PM in Net

Saturday, 15 April 2006

Using Config Files to Manage DataDrivenTesting in VSTS

I've posted about Data Driven Testing before, unfortunately that solution (setting the DataDirectory attribute) no longer works. It looks like the between Beta3 (when the entry was written) and the release the way the test code was parsed has changed. Setting the DataDirectory now fails to work. A colleague of mine (Simon Horrell) came up with a better solution which I thought I'd document more fully here.

When using the DataSource attribute in the testing code you can, rather than entering all the details for the attribute, instead refer to an App.config file. This file would then contain the connection string and the other details needed by the data source.

This makes our code look like this

[TestMethod]
[DataSource("dataDrivenTestingDS")]
public void TestFirePhotonTorpedoe()
{
    // code here
}
This refers to an entry in an app.config file called "dataDrivenTestingDS". This entry is part of a custom configuration section parsed by the testing framework.

To get this code to work you need to add an App.config file to your testing project. This file will need to have three configuration sections. The first is for the connection string that would appear in the DataSource attribute of the test. You also need to add a configuration section handler that is part of the unit testing framework. This custom handler parsers a section called DataSources that contains the information the DataSource attribute needs.

The config file looks like this

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="microsoft.visualstudio.testtools" 
        type="Microsoft.VisualStudio.TestTools.UnitTesting.TestConfigurationSection, 
Microsoft.VisualStudio.QualityTools.UnitTestFramework, 
Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
  </configSections>
  <connectionStrings>
    <add name="dataDrivenTesting" 
connectionString="server=.\SQLExpress;AttachDBFilename=|DataDirectory|\StarShipTest.mdf;Integrated 
Security=True" providerName="System.Data.SqlClient"/>
  </connectionStrings>
  <microsoft.visualstudio.testtools>
    <dataSources>
      <add name="dataDrivenTestingDS" connectionString="dataDrivenTesting"
        dataTableName="FireTorpedoesTest" dataAccessMethod="Sequential"/>
    </dataSources>
  </microsoft.visualstudio.testtools>
</configuration>
This doesn't quite get you all the way home as the data base still has to becopied to the 'out' directory wasting space, and hardcoding the fully qualified directory name is not an option (the config file should be under source control). This means we need to amend the App.config file to use an external per user file containing the user's settings, something like this.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="microsoft.visualstudio.testtools" 
        type="Microsoft.VisualStudio.TestTools.UnitTesting.TestConfigurationSection, 
Microsoft.VisualStudio.QualityTools.UnitTestFramework, 
Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
  </configSections>
  <connectionStrings configSource="mysettings.config">
  </connectionStrings>
  <microsoft.visualstudio.testtools>
    <dataSources>
      <add name="dataDrivenTestingDS" connectionString="dataDrivenTesting"
        dataTableName="FireTorpedoesTest" dataAccessMethod="Sequential"/>
    </dataSources>
  </microsoft.visualstudio.testtools>
</configuration>
and the external configuration file contains the following
<connectionStrings>
  <add name="dataDrivenTesting" connectionString="server=.\SQLExpress;AttachDBFilename=c:\datadirectory\StarShipTest.mdf;Integrated 
Security=True" providerName="System.Data.SqlClient"/>
</connectionStrings>
You need to remember to deploy the per user config file (mysettings.config above) to the 'out' directory (the App.config is deployed and renamed automatically by Visual Studio), I typically do this in the testrunconfig configuration file.

Your developers can check the App.confg into source control and keep the mysettings.config only on their local machine.

Posted by kevin at 7:10 PM in Net

« April »
SunMonTueWedThuFriSat
      1
2345678
9101112131415
16171819202122
23242526272829
30