LTAF is an integration test framework developed by the Microsoft ASP.NET QA Team. Integration tests are different than unit tests, they actually test what a user would be doing by opening up the browser and filling in textboxes or clicking links. LTAF is nice because you write your tests in C# and run them in the browser of your choice, the disadvantage to this is you can’t have it easily integrate with a continuous integration system like CruiseControl.NET since there is no runner.
To get started with LTAF, you can download the latest release from the ASP.NET QA Page on CodePlex. As of the June release they didn’t have a binary release of it, your only options are either download the source and build it yourself or grab the sample application and pull it from its bin/ folder (this is what we’ll use). You need to steal 3 files from the sample application:
- bin/Microsoft.Web.Testing.Lightweight.dll
- Test/Default.aspx
- Test/DriverPage.aspx
If you don’t want to type all this, You can download my example code here, which includes both ASP.NET WebForms and MVC examples.
Add a reference to the dll and include the Test pages in your website somewhere (I just include the whole Test/ folder). Now you are ready to write your first integration tests with LTAF. You can add your tests in their own library and reference them from your web application or just include them right in your site, LTAF will just scan all assemblys for classes marked with the [WebTestClass] attribute. First, lets create a page to test:
<asp:label runat="server" id="lblMessages"> </asp:label><asp:label runat="server" id="lblUserName"> <asp:textbox runat="server" id="txtUserName"> <asp:button runat="server" id="btnSubmit" onclick="btnSubmit_Click" text="Submit"></asp:button> </asp:textbox></asp:label>
protected void btnSubmit_Click(object sender, EventArgs e) { this.lblMessages.Text = String.Format("Hello, {0}", this.txtUserName.Text); }
and now lets add a class called Tests.cs into the Test/ folder:
[WebTestClass] public class Tests { [WebTestMethod] public void Test_User_Can_Submit_UserName() { HtmlPage page = new HtmlPage("/Default.aspx"); page.Elements.Find("txtUserName").SetText("John Anderson"); page.Elements.Find("btnSubmit").Click(WaitFor.Postback); Assert.StringContains(page.Elements.Find("lblMessages").GetInnerText(), "John Anderson"); } }
You can go to your site’s Test/ folder and run your tests and that is all it takes to start doing integration tests with ASP.NET and LTAF.

