Integration Tests with Lightweight Test Automation Framework (LTAF) and ASP.NET

Tags: asp.net c# ltaf

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:Label>

<asp:TextBox runat="server" ID="txtUserName"></asp:TextBox>

<asp:Button runat="server" ID="btnSubmit" onclick="btnSubmit_Click" Text="Submit" />


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, it should look something like this:
screenshot of LTAF


and that is all it takes to start doing integration tests with ASP.NET and LTAF.

Comments
2010-03-05 17:42:26 - Gail Reitter

Thanks for the article, your website looks solid! I've fallen behind staying updated with the Oscar nominees this past year but this totally helped. So excited for Sunday!

2010-03-05 20:06:54 - Josue Gargan

This is certainly my initial stop by and I really like what I'm seeing. Your weblog is so much fun to look over, quite compelling as well as informative. I'll undoubtedly recommend it to my friends. Nevertheless, I did have some problem with the commenting. It kept giving me an problem whenever I clicked on publish comment. I hope, that can be fixed. Many thanks

2010-03-06 01:19:05 - Blue Cross Tonik

I was just looking around for related posts for my project research and I happened to stumble upon this. Thanks for the great information.

2010-03-06 19:46:33 - Peter

Great Post. I would love to read more in future. keep up the good work. Yearly hosting http://www.intelweb.biz

2010-03-08 02:59:29 - Kenneth

I visit your website once in a while and I just have to mention that I like your template!

2010-03-08 03:24:50 - Cyrus

Hi, I run across this web site by on a fluke when I was going through Google then I popped in to your site. I must say your website is interesting I love your theme! At this moment I don’t have much free-time at the current moment to fully read through your sitebut I bookmarked it. I will come back in a day or two. Thanks for a great site.

2010-03-08 04:49:07 - Merrill

Hello everybody, This website is enjoyable and so is how the subject matter was explained. I like some of the comments as well although I would prefer we all keep it on topic so that to add value to the message. It will be also encouraging to the one who penned it down if we all could pass it around (for many of us who use bookmarking services such as a reddit, facebook,..). Again, Thanks..

2010-03-08 04:54:01 - ghd hair straighteners cheap

Really intriguing story, something comparable to this happened to me not too long ago and it pretty much played out in the same way to how you describe it.

2010-03-08 05:05:38 - Charles

Thanks for sharing information. Your information will be useful to people who are going to do CompTIA A+ exam.Nowadays many of the people like to do certification to improve their career.

2010-03-08 07:57:56 - Contractor Accountants

Great post. Thanks for an interesting read. I've just subscribed to this blog so I'll be back soon! Cheers

2010-03-09 07:22:45 - Kartenlegen per email

thanks for the Info. I often read here...

2010-03-10 00:01:46 - Deshawn Cretsinger

Hello i just stumbled your blog from Bing and been reading some of your entries and just wondering why you selected a Wordpress site dont you find it hard to do anything with? Also a security concern?

2010-03-10 03:00:02 - contractor mortgages

Wow. Thank you for a really insightful post. I'll add your RSS feed to my Google Reader account now. Looking forward to more of the same in 2010!

2010-03-10 10:02:44 - Sports Betting

Thanks for posting this. I actually agree with you.

2010-03-10 17:18:27 - Santos Segota

Looks like the link is gone can anyone provide a re upload? Thanks!

2010-03-10 20:41:53 - reverse white

It is refreshing page The particular details I came across helpful. I have saved it and definately will surf to once again afterwards. Thanks a ton.

2010-03-11 06:33:39 - Affiliate program network

This is nothing new , about the time. It's called evolution. The best thing to do, in this time is to register to some affiliate program network and start a business on your own with their help. Otherwise we'll become slaves.

2010-03-11 10:24:27 - online new movies free

Me and my friend were arguing about an issue similar to this! Now I know that I was right. lol! Thanks for the information you post.

2010-03-11 10:44:03 - reversewhitepages

It's nice post All the advice I stumbled onto helpful. We have made note of it and will eventually visit back again later. Thanks.

2010-03-11 16:07:53 - reversewhite

It's very good blog The info I stubled onto valuable. We've saved it and definately will surf to all over again shortly after. With thanks.

2010-03-11 16:32:22 - horde leveling guide

Admiring the time and effort you put into your blog and detailed information you offer! I will bookmark your blog and have my children check up here often. Thumbs up!

2010-03-11 16:37:01 - reverse white

It's very good site All the specifics I uncovered helpful. I have made note of it and definately will surf to back again later. With thanks.

2010-03-12 01:36:57 - horde leveling guide

Admiring the time and effort you put into your blog and detailed information you offer! I will bookmark your blog and have my children check up here often. Thumbs up!

2010-03-13 05:33:30 - Hipolito M. Wiseman

Considerably, your site is definately the best on this worthy topic. I harmonize with you and will very much look forward to your approaching updates.

2010-03-13 11:44:24 - Andrew A. Sailer

I will instantly grab your rss feed to stay abreast of any updates. Gratifying work!

2010-03-13 23:10:45 - Sales Agent

Another UNIVERSAL WEB PROMOTERS First Setting The Standards In Web-Promotion. Simply Deemed The NUCLEAR BLAST. And, Without A Doubt The Next Advertising Craze. No Other Company Has Ever Placed A SOLO-AD In Front Of Such A Large Audience On Over 2 BILLION High-Traffic Websites And Its Just $14.95. If This Sounds Good Visit Our Website. We Guarantee A Low-Cost And Effective Advertising Service To Fit Your Needs.

2010-03-14 04:51:57 - VsConz

Thanks ! Very helpful post!

2010-03-14 15:32:34 - Andrew Pelt

I want to immediately grab your rss feed to stay abreast of any updates, but I cant find it, do you have one?