KEMBAR78
Testing ASP.net Web Applications using Ruby | PPTX
Testing ASP.net using RubyMeerkatalyst@Ben_HallBen@BenHall.me.ukBlog.BenHall.me.uk
UK based C# MVPWeb Developer @ 7digital.com Working on a number of Open Source ProjectsCo-Author of Testing ASP.net Web Applicationshttp://www.testingaspnet.com
1|	Why you should care2|	Object Level testing3|	UI level testing
What do I mean by Testing ASP.net?
WHY?http://www.flickr.com/photos/atomicpuppy/2132073976/
It is 2010. Automated testing is no longer controversial.
[TestMethod()] public void DebitTest() {     	string customerName = "Mr. Bryan Walton";     	double balance = 11.99;     BankAccount target = new BankAccount(customerName, balance);     	double amount = 11.22;     target.Debit(amount);     Assert.AreEqual((System.Convert.ToDouble(0.77)), target.Balance, 0.05); // 0.05 is tolerance for floating-point comparison     	//Assert.Inconclusive("A method that does not return a value cannot be verified."); }
[TestMethod()] public void DebitTest() {     	string customerName = "Mr. Bryan Walton";     	double balance = 11.99;     BankAccount target = new BankAccount(customerName, balance);     	double amount = 11.22;     target.Debit(amount);     Assert.AreEqual((System.Convert.ToDouble(0.77)), target.Balance, 0.05); // 0.05 is tolerance for floating-point comparison     //Assert.Inconclusive("A method that does not return a value cannot be verified."); }
[Story] public void Should_find_customers_by_name_when_name_matches() { 	Story story = new Story("List customers by name"); story.AsA("customer support staff") 		.IWant("to search for customers in a very flexible manner") 		.SoThat("I can find a customer record and provide meaningful support"); CustomerRepository repo = null;	 Customer customer = null; story.WithScenario("Find by name") 		.Given("a set of valid customers", delegate { repo = CreateDummyRepo(); }) 		.When("I ask for an existing name", "Joe Schmoe", delegate(string name) { customer = repo.FindByName(name); }) 		.Then("the correct customer is found and returned", delegate 	{Assert.That(customer.Name, Is.EqualTo("Joe Schmoe"));}); }
=()=>
[Description]  public class Transferring_between_from_account_and_to_account  {    static Account fromAccount;    static Account toAccount;      Context before_each =()=>    {      fromAccount = new Account {Balance = 1m};      toAccount = new Account {Balance = 1m};    };        When the_transfer_is_made =()=>    {      fromAccount.Transfer(1m, toAccount);    };         It should_debit_the_from_account_by_the_amount_transferred =()=>    {      fromAccount.Balance.ShouldEqual(0m);    };      It should_credit_the_to_account_by_the_amount_transferred =()=>    {      toAccount.Balance.ShouldEqual(2m);    };  }  
[Test]public void WatiNSearchText_SearchWatiN_TextDisplayedOnScreen(){    IE ie = new IE("http://localhost:49992/WatiNSite/");    ie.TextField(Find.ByName("searchText")).TypeText("WatiN");    ie.Button(Find.ByValue("Search")).Click();    bool result = ie.Text.Contains("WatiN");    Assert.IsTrue(result); }
You can make C# readableBut it’s hard
RECORD AND PLAYBACKhttp://www.flickr.com/photos/gagilas/2659695352/
http://www.flickr.com/photos/buro9/298994863/WHY RUBY?
http://www.flickr.com/photos/mag3737/1914076277/
RSpechttp://www.flickr.com/photos/dodgsun/467076780/
Behaviour Driven Development
describe MyObject doit “should do something cool” do	endend
[TestMethod()] public void DebitTest() {     	string customerName = "Mr. Bryan Walton";     	double balance = 11.99;     BankAccount target = new BankAccount(customerName, balance);     	double amount = 11.22;     target.Debit(amount);     Assert.AreEqual((System.Convert.ToDouble(0.77)), target.Balance, 0.05); // 0.05 is tolerance for floating-point comparison     	//Assert.Inconclusive("A method that does not return a value cannot be verified."); }
describe BankAccount, “Transactions” do   it “can debit pence from an account” docustomer_name = "Mr. Bryan Walton";     current_balance = 1.50;          account = BankAccount(customer_name, current_balance).newamount_to_debit = 1.25;    account.Debit(amount);     account.Balance.should == 0.25   endend
describe BankAccount, “Transactions” do   before(:each) docurrent_balance = 1.50;          @account = BankAccount.new("Mr. Bryan Walton", current_balance)   end   it “can debit pence from an account” doamount_to_debit = 1.25          @account.Debit amount      @account.Balance.should == 0.25   endend
Intent
IronRuby
Thank  you
DEMORSpec
Outside-in Development
Executable Specification
Cucumberhttp://www.flickr.com/photos/vizzzual-dot-com/2738586453/
Feature: Creating a schedule	In Order to book meetings	The manager	Needs to be able to view a teams calendarScenario: View calendar of another viewGivenBob has a public calendarWhen the manager views Bob’s calendarThen an empty calendar should be shown
Given/^([^\"]*) has a public calendar$/ do |user|end
When /^ the manager views ([^\"]*)’s calendar$/ do |user|end
Then /^ an empty calendar should be shown $/ doend
[Story] public void Should_find_customers_by_name_when_name_matches() { 	Story story = new Story("List customers by name"); story.AsA("customer support staff") 		.IWant("to search for customers in a very flexible manner") 		.SoThat("I can find a customer record and provide meaningful support"); CustomerRepository repo = null;	 Customer customer = null; story.WithScenario("Find by name") 		.Given("a set of valid customers", delegate { repo = CreateDummyRepo(); }) 		.When("I ask for an existing name", "Joe Schmoe", delegate(string name) { customer = repo.FindByName(name); }) 		.Then("the correct customer is found and returned", delegate 	{Assert.That(customer.Name, Is.EqualTo("Joe Schmoe"));}); }
Feature: List customers by name  As a customer support staff  I want to search for customers in a very flexible manner  So that I can find a customer record and provide meaningful supportScenario: Find by name   Given a set of valid customers  When I ask for an existing name  Then the correct customer is found and returned
NOT BEST PRACTICE!!Given /^a set of valid customers$/ do     @repo = CreateDummyRepo()endWhen /^I ask for an existing name$/ do    @customer = @repo.FindByName("Joe Schmoe")endThen /^the correct customer is found and returned$/ do    @customer.Name.should == "Joe Schmoe“end
WebRathttp://www.flickr.com/photos/whatwhat/22624256/
visitclick_linkfill_inclick_buttoncheck and uncheckchooseselectattach_file
DEMOCucumber, WebRat and Automated UI testing
Where are 7digital?http://www.flickr.com/photos/michelangelo_mi/1314320102/
One more thing...
Meerkatalyst
http://www.flickr.com/photos/leon_homan/2856628778/
Expressing intent
http://www.flickr.com/photos/philliecasablanca/2456840986/@Ben_HallBen@BenHall.me.ukBlog.BenHall.me.uk
using Cuke4Nuke.Framework;usingNUnit.Framework;usingWatiN.Core;namespaceGoogle.StepDefinitions{    publicclassSearchSteps    {        Browser _browser;         [Before]        publicvoidSetUp()        {            _browser = new WatiN.Core.IE();        }        [After]        publicvoidTearDown()        {            if (_browser != null)            {                _browser.Dispose();            }        }        [When(@"^(?:I'm on|I go to) the search page$")]        publicvoidGoToSearchPage()        {            _browser.GoTo("http://www.google.com/");        }        [When("^I search for \"(.*)\"$")]        publicvoidSearchFor(string query)        {            _browser.TextField(Find.ByName("q")).TypeText(query);            _browser.Button(Find.ByName("btnG")).Click();        }        [Then("^I should be on the search page$")]        publicvoidIsOnSearchPage()        {            Assert.That(_browser.Title == "Google");        }        [Then("^I should see \"(.*)\" in the results$")]        publicvoidResultsContain(stringexpectedResult)        {            Assert.That(_browser.ContainsText(expectedResult));        }    }}
Given /^(?:I'm on|I go to) the search page$/ do  visit 'http://www.google.com'end When /^I search for "([^\"]*)"$/ do|query|  fill_in 'q', :with => query  click_button 'Google Search'end Then /^I should be on the search page$/ do dom.search('title').should == "Google"end Then /^I should see \"(.*)\" in the results$/ do|text|  response.should contain(text)end
SoftwareRecommended:IronRubyRubyCucumberRspecWebRatmechanizeSelenium RCselenium-clientCaricatureactiverecord-sqlserver-adapterOptional:XSP \ MonoJetBrain’sRubyMineJRubyCapybaraCelerityActive record active-record-model-generatorFakerGuid
Useful Linkshttp://www.github.com/BenHallhttp://blog.benhall.me.ukhttp://stevehodgkiss.com/2009/11/14/using-activerecord-migrator-standalone-with-sqlite-and-sqlserver-on-windows.htmlhttp://www.testingaspnet.comhttp://http://msdn.microsoft.com/en-us/magazine/dd434651.aspxhttp://msdn.microsoft.com/en-us/magazine/dd453038.aspxhttp://www.cukes.info
Getting SQL Server to workgem install activerecord-sqlserver-adapterDownload dbi-0.2.2.zip Extract dbd\ADO.rb to ruby\site_ruby\1.8\DBD\ADO.rb

Testing ASP.net Web Applications using Ruby