Freigeben über


Running tests in Team Build - 3

What do I need to do to run Web tests/ASP.NET unit tests with Team Foundation Build?
ASP.NET unit tests or Web tests can be run on Web sites deployed using Web Development server or IIS. For any test, the deploying server must be specified. The examples below show the code to be written for each:
Running an ASP.NET unit test on a Web site hosted on WDS
/// <summary>
///A test for LibClass in Website1
///</summary>
[TestMethod()]
[HostType("ASP.NET")]
[AspNetDevelopmentServerHost("%PathToWebRoot%\\WebSite1", "/WebSite1")]
public void ConstructorTest()
{
object target = TestProject1.Class1Accessor.CreatePrivate();

// Code to verify functionality
}

Running an ASP.NET unit test on a Web site hosted on IIS
/// <summary>
///A test for GetOne ()
///</summary>
[TestMethod()]
[HostType("ASP.NET")]
[UrlToTest("https://localhost/Website3")]
public void GetOneTest()
{
object target = TestProject3.Class1Accessor.CreatePrivate();

     // Code to verify functionality
}

Running an ASP.NET unit test on a Web service hosted on WDS
/// <summary>
///A test for HelloWorld ()
///</summary>

[AspNetDevelopmentServer("MyServer", @"%PathToWebRoot%\Webservice1", "/Webservice1")]
[TestMethod()]
public void HelloWorldTest()
{
Service target = new Service();
WebServiceHelper.TryUrlRedirection(target, this.testContextInstance, "MyServer");
string expected = "Hello World";
string actual;
actual = target.HelloWorld();

     Assert.AreEqual(expected, actual);
}

Running an ASP.NET unit test on a Web service hosted on IIS
[UrlToTest("https://localhost/Webservice1")]
[TestMethod()]
public void HelloWorldTest1()
{
Service target = new Service();

// Code to verify functionality
}

Running a Web test on a Web site/service hosted on WDS

Once the Web test is created, click the "Parameterize Web Server" button on the tool window. The Parameterize Web Servers dialog box opens displaying a Change… button to its right. Click the button. A dialog box opens allowing you to choose between Web server or ASP.NET Development Server. Select the "ASP.NET Development Server" option. The values for the server root and the Website root are pre-populated as shown.

PathToWebRoot is an environment variable that points to the binaries and source code of the Web site. On the build machine, this is set to the _PublishedWebsites folder in the build directory.

How do I associate test results of tests that I ran outside the build process with a build?

In the Test Results window, select the test run containing the results you want to publish to the build. In the Team Explorer window, click the team project containing the build the test results have to be published to. Now, click the "Publish Results" button in the tool window. In the dialog box that appears, you are prompted to choose the build name that the test results have to be published to as well as the platform and flavor that the results are to be published to. Code coverage data can also be uploaded if the Include code coverage data for selected runs option is selected. Click OK and the test results are uploaded.

That concludes the "Running tests in Team Build" series! Waiting to hear from you folks...

Comments

  • Anonymous
    June 21, 2007
    How do we configure to run the website on a specific port. We are doing test automation and integrating with the build process and we need the URL with fixed for our automation testing.