Click here to Skip to main content
11,709,844 members (51,606 online)
Click here to Skip to main content

Tagged as

Running UI Tests on Local ASP.NET Website with Development Server

, 25 Jun 2012 CPOL 4.9K 2
Rate this:
Please Sign up or sign in to vote.
These past couple of days I started writing a utility program that will invoke some UI tests against a certain website of my choice.

These past couple of days I started writing a utility program that will invoke some UI tests against a certain website of my choice. Obviously, I needed to write tests for the functionality of this utility, so I will be sure that it works. I wanted the tests to be as real as possible, and so I decided to run them against a real site, like google (could've been any other site, this doesn't really matter for the sake of the story).

The tests worked great, but then I realized that they could easily be broken, with no connection to my work - No one promises me that google's page structure (or anything I want to test) will always stay the same, and I don't even know which tests i'll want to add to it in the future, and if I'll have all the resources on the site of my choice.

I decided that I'll create a custom mvc site for the sake of my tests. At first I configured the site on IIS locally and this was great, but then I started thinking another step forward, and realized I have another problem - I want someone else to be able to download the source code, and run the tests immediately without having to create a local website and going through all the proper configurations.

I realized that I could use the development server for this.
First, I needed to give the site a static port to run on in the development server :

(In the project properties page, go to the 'Web' tab, and mark 'Use Visual Studio Development Server' -> 'Specific Port')

Then, I created a class called 'DevelopmentServer' responsible for loading the ASP.NET development server, and shutting it down at the end :

public class DevelopmentServer : IDisposable
    private readonly Process _devServer;

    public static int Port = 1212;
    private string _devServerExe = @"C:\Program Files (x86)\Common Files\microsoft shared\DevServer\10.0\WebDev.WebServer40.EXE";
    private string _testSitePath = @"C:\Dev\MySitePath\";

    public DevelopmentServer()
        _devServer = new Process {
            StartInfo = { 
                FileName = _devServerExe,
                Arguments = string.Format("/port:{0} /path:{1}", Port, _testSitePath)

            Console.WriteLine("Unable to start development server");

    public void Dispose()

The port number and the library paths are just hard coded for the sake of the example. It makes more sense to put them in some configuration file of your choice. (Note: You might have to change the path to the file WebDev.WebServer40.exe which is the binary of the development server, according to the version you have. The earlier version of this file is called WebDev.WebServer20.exe)

Finally, I just created an instance of this class upon FixtureSetUp, and disposed of it on FixtureTearDown.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Gilly Barr
Web Developer
Israel Israel
Started programming e-commerce sites with PHP & MySQL at the age of 14. Worked for me well for about 5 years.

Transfered to C# &, while serving in the IDF.

Currently working as a web developer for Sears Israel (SHC).

Check out my blog!

You may also be interested in...

Comments and Discussions

-- There are no messages in this forum --
| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150819.1 | Last Updated 25 Jun 2012
Article Copyright 2012 by Gilly Barr
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid