Saturday, 16 February 2008

Using the MSTest AspNetDevelopmentServer Attribute

If you want to have Integration-type tests and run automated tests against a web service (or web site), with MSTest you can use the "AspNetDevelopmentServer" Attribute on your Test Method. There is a gotcha with the use of this attribute. See the following example:

[TestClass]

public class MyTestClass

{

    [TestMethod]

    [AspNetDevelopmentServer("name", "path")]

    public void MyTestMethod()

    {

        // Do stuff

    }

}



You might be tempted to put the "name" and "path" properties in constants somewhere. Unfortunately if you do this, the "AspNetDevelopmentServer" Attribute will cease to function and the ASP.NET Development Server will not be activated when your tests run. Why is a mystery. So, keep the property values as hard-coded strings in-line.

1 comments:

Carl J said...

You can add this to the test config file, or through the Test menu and Edit Test config

About Me