Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Testing ASP.net using Ruby<br />Meerkatalyst<br />@Ben_HallBen@BenHall.me.ukBlog.BenHall.me.uk<br />
UK based C# MVPWeb Developer @ 7digital.com Working on a number of Open Source Projects<br />Co-Author of <br />Testing AS...
1|	Why you should care2|	Object Level testing3|	UI level testing<br />
What do I mean by Testing ASP.net?<br />
WHY?<br />http://www.flickr.com/photos/atomicpuppy/2132073976/<br />
It is 2010. Automated testing is no longer controversial.<br />
[TestMethod()] public void DebitTest() {     	string customerName = &quot;Mr. Bryan Walton&quot;;     	double balance = 11...
[TestMethod()] public void DebitTest() {     	string customerName = &quot;Mr. Bryan Walton&quot;;     	double balance = 11...
[Story] public void Should_find_customers_by_name_when_name_matches() { 	Story story = new Story(&quot;List customers by n...
=()=&gt;<br />
[Description]  public class Transferring_between_from_account_and_to_account  {    static Account fromAccount;    static A...
[Test]public void WatiNSearchText_SearchWatiN_TextDisplayedOnScreen(){    IE ie = new IE(&quot;http://localhost:49992/Wati...
You can make C# readable<br />But it’s hard<br />
RECORD AND PLAYBACK<br />http://www.flickr.com/photos/gagilas/2659695352/<br />
http://www.flickr.com/photos/buro9/298994863/<br />WHY RUBY?<br />
http://www.flickr.com/photos/mag3737/1914076277/<br />
RSpec<br />http://www.flickr.com/photos/dodgsun/467076780/<br />
Behaviour Driven Development<br />
describe MyObject do<br />it “should do something cool” do<br />	end<br />end<br />
[TestMethod()] public void DebitTest() {     	string customerName = &quot;Mr. Bryan Walton&quot;;     	double balance = 11...
describe BankAccount, “Transactions” do   it “can debit pence from an account” docustomer_name = &quot;Mr. Bryan Walton&qu...
describe BankAccount, “Transactions” do   before(:each) docurrent_balance = 1.50;          @account = BankAccount.new(&quo...
Intent<br />
IronRuby<br />
Thank  you<br />
DEMO<br />RSpec<br />
Outside-in Development<br />
Executable Specification<br />
Cucumber<br />http://www.flickr.com/photos/vizzzual-dot-com/2738586453/<br />
Feature: Creating a schedule<br />	In Order to book meetings<br />	The manager<br />	Needs to be able to view a teams cale...
Given/^([^&quot;]*) has a public calendar$/ do |user|<br />end<br />
When /^ the manager views ([^&quot;]*)’s calendar$/ do |user|<br />end<br />
Then /^ an empty calendar should be shown $/ do<br />end<br />
[Story] public void Should_find_customers_by_name_when_name_matches() { 	Story story = new Story(&quot;List customers by n...
Feature: List customers by name  As a customer support staff  I want to search for customers in a very flexible manner  So...
NOT BEST PRACTICE!!<br />Given /^a set of valid customers$/ do     @repo = CreateDummyRepo()endWhen /^I ask for an existin...
WebRat<br />http://www.flickr.com/photos/whatwhat/22624256/<br />
visit<br />click_link<br />fill_in<br />click_button<br />check and uncheck<br />choose<br />select<br />attach_file<br />
DEMO<br />Cucumber, WebRat and Automated UI testing<br />
Where are 7digital?<br />http://www.flickr.com/photos/michelangelo_mi/1314320102/<br />
One more thing...<br />
Meerkatalyst<br />
http://www.flickr.com/photos/leon_homan/2856628778/<br />
Expressing intent<br />
http://www.flickr.com/photos/philliecasablanca/2456840986/<br />@Ben_HallBen@BenHall.me.ukBlog.BenHall.me.uk<br />
using Cuke4Nuke.Framework;<br />usingNUnit.Framework;<br />usingWatiN.Core;<br />namespaceGoogle.StepDefinitions<br />{<br...
Given /^(?:I&apos;m on|I go to) the search page$/ do<br />  visit &apos;http://www.google.com&apos;<br />end<br /> <br />W...
Software<br />Recommended:<br />IronRuby<br />Ruby<br />Cucumber<br />Rspec<br />WebRat<br />mechanize<br />Selenium RC<br...
Useful Links<br />http://www.github.com/BenHall<br />http://blog.benhall.me.uk<br />http://stevehodgkiss.com/2009/11/14/us...
Getting SQL Server to work<br />gem install activerecord-sqlserver-adapter<br />Download dbi-0.2.2.zip <br />Extract dbdAD...
Upcoming SlideShare
Loading in …5
×

Testing ASP.net Web Applications using Ruby

3,732 views

Published on

Presentation from CodeMash on 14th January 2010.

Code-samples can be found at http://github.com/BenHall/Kona

Published in: Technology

Testing ASP.net Web Applications using Ruby

  1. Testing ASP.net using Ruby<br />Meerkatalyst<br />@Ben_HallBen@BenHall.me.ukBlog.BenHall.me.uk<br />
  2. UK based C# MVPWeb Developer @ 7digital.com Working on a number of Open Source Projects<br />Co-Author of <br />Testing ASP.net Web Applications<br />http://www.testingaspnet.com<br />
  3. 1| Why you should care2| Object Level testing3| UI level testing<br />
  4. What do I mean by Testing ASP.net?<br />
  5. WHY?<br />http://www.flickr.com/photos/atomicpuppy/2132073976/<br />
  6. It is 2010. Automated testing is no longer controversial.<br />
  7. [TestMethod()] public void DebitTest() {      string customerName = &quot;Mr. Bryan Walton&quot;;      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(&quot;A method that does not return a value cannot be verified.&quot;); }<br />
  8. [TestMethod()] public void DebitTest() {      string customerName = &quot;Mr. Bryan Walton&quot;;      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(&quot;A method that does not return a value cannot be verified.&quot;); }<br />
  9. [Story] public void Should_find_customers_by_name_when_name_matches() { Story story = new Story(&quot;List customers by name&quot;); story.AsA(&quot;customer support staff&quot;) .IWant(&quot;to search for customers in a very flexible manner&quot;) .SoThat(&quot;I can find a customer record and provide meaningful support&quot;); CustomerRepository repo = null; Customer customer = null; story.WithScenario(&quot;Find by name&quot;) .Given(&quot;a set of valid customers&quot;, delegate { repo = CreateDummyRepo(); }) .When(&quot;I ask for an existing name&quot;, &quot;Joe Schmoe&quot;, delegate(string name) { customer = repo.FindByName(name); }) .Then(&quot;the correct customer is found and returned&quot;, delegate {Assert.That(customer.Name, Is.EqualTo(&quot;Joe Schmoe&quot;));}); }<br />
  10. =()=&gt;<br />
  11. [Description]  public class Transferring_between_from_account_and_to_account  {    static Account fromAccount;    static Account toAccount;      Context before_each =()=&gt;    {      fromAccount = new Account {Balance = 1m};      toAccount = new Account {Balance = 1m};    };        When the_transfer_is_made =()=&gt;    {      fromAccount.Transfer(1m, toAccount);    };         It should_debit_the_from_account_by_the_amount_transferred =()=&gt;    {      fromAccount.Balance.ShouldEqual(0m);    };      It should_credit_the_to_account_by_the_amount_transferred =()=&gt;    {      toAccount.Balance.ShouldEqual(2m);    };  }  <br />
  12. [Test]public void WatiNSearchText_SearchWatiN_TextDisplayedOnScreen(){    IE ie = new IE(&quot;http://localhost:49992/WatiNSite/&quot;);    ie.TextField(Find.ByName(&quot;searchText&quot;)).TypeText(&quot;WatiN&quot;);    ie.Button(Find.ByValue(&quot;Search&quot;)).Click();    bool result = ie.Text.Contains(&quot;WatiN&quot;);    Assert.IsTrue(result); }<br />
  13. You can make C# readable<br />But it’s hard<br />
  14. RECORD AND PLAYBACK<br />http://www.flickr.com/photos/gagilas/2659695352/<br />
  15. http://www.flickr.com/photos/buro9/298994863/<br />WHY RUBY?<br />
  16. http://www.flickr.com/photos/mag3737/1914076277/<br />
  17. RSpec<br />http://www.flickr.com/photos/dodgsun/467076780/<br />
  18. Behaviour Driven Development<br />
  19. describe MyObject do<br />it “should do something cool” do<br /> end<br />end<br />
  20. [TestMethod()] public void DebitTest() {      string customerName = &quot;Mr. Bryan Walton&quot;;      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(&quot;A method that does not return a value cannot be verified.&quot;); }<br />
  21. describe BankAccount, “Transactions” do it “can debit pence from an account” docustomer_name = &quot;Mr. Bryan Walton&quot;;     current_balance = 1.50;     account = BankAccount(customer_name, current_balance).newamount_to_debit = 1.25;    account.Debit(amount);     account.Balance.should == 0.25 endend<br />
  22. describe BankAccount, “Transactions” do before(:each) docurrent_balance = 1.50;     @account = BankAccount.new(&quot;Mr. Bryan Walton&quot;, current_balance) end it “can debit pence from an account” doamount_to_debit = 1.25     @account.Debit amount @account.Balance.should == 0.25 endend<br />
  23. Intent<br />
  24. IronRuby<br />
  25. Thank you<br />
  26. DEMO<br />RSpec<br />
  27. Outside-in Development<br />
  28. Executable Specification<br />
  29. Cucumber<br />http://www.flickr.com/photos/vizzzual-dot-com/2738586453/<br />
  30. Feature: Creating a schedule<br /> In Order to book meetings<br /> The manager<br /> Needs to be able to view a teams calendar<br />Scenario: View calendar of another view<br />GivenBob has a public calendar<br />When the manager views Bob’s calendar<br />Then an empty calendar should be shown<br />
  31. Given/^([^&quot;]*) has a public calendar$/ do |user|<br />end<br />
  32. When /^ the manager views ([^&quot;]*)’s calendar$/ do |user|<br />end<br />
  33. Then /^ an empty calendar should be shown $/ do<br />end<br />
  34. [Story] public void Should_find_customers_by_name_when_name_matches() { Story story = new Story(&quot;List customers by name&quot;); story.AsA(&quot;customer support staff&quot;) .IWant(&quot;to search for customers in a very flexible manner&quot;) .SoThat(&quot;I can find a customer record and provide meaningful support&quot;); CustomerRepository repo = null; Customer customer = null; story.WithScenario(&quot;Find by name&quot;) .Given(&quot;a set of valid customers&quot;, delegate { repo = CreateDummyRepo(); }) .When(&quot;I ask for an existing name&quot;, &quot;Joe Schmoe&quot;, delegate(string name) { customer = repo.FindByName(name); }) .Then(&quot;the correct customer is found and returned&quot;, delegate {Assert.That(customer.Name, Is.EqualTo(&quot;Joe Schmoe&quot;));}); }<br />
  35. 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<br />
  36. NOT BEST PRACTICE!!<br />Given /^a set of valid customers$/ do @repo = CreateDummyRepo()endWhen /^I ask for an existing name$/ do @customer = @repo.FindByName(&quot;Joe Schmoe&quot;)endThen /^the correct customer is found and returned$/ do @customer.Name.should == &quot;Joe Schmoe“end<br />
  37. WebRat<br />http://www.flickr.com/photos/whatwhat/22624256/<br />
  38. visit<br />click_link<br />fill_in<br />click_button<br />check and uncheck<br />choose<br />select<br />attach_file<br />
  39. DEMO<br />Cucumber, WebRat and Automated UI testing<br />
  40. Where are 7digital?<br />http://www.flickr.com/photos/michelangelo_mi/1314320102/<br />
  41. One more thing...<br />
  42. Meerkatalyst<br />
  43. http://www.flickr.com/photos/leon_homan/2856628778/<br />
  44. Expressing intent<br />
  45. http://www.flickr.com/photos/philliecasablanca/2456840986/<br />@Ben_HallBen@BenHall.me.ukBlog.BenHall.me.uk<br />
  46. using Cuke4Nuke.Framework;<br />usingNUnit.Framework;<br />usingWatiN.Core;<br />namespaceGoogle.StepDefinitions<br />{<br />    publicclassSearchSteps<br />    {<br />        Browser _browser;<br /> [Before]<br />        publicvoidSetUp()<br />        {<br />            _browser = new WatiN.Core.IE();<br />        }<br /> [After]<br />        publicvoidTearDown()<br />        {<br />            if (_browser != null)<br />            {<br />                _browser.Dispose();<br />            }<br />        }<br /> [When(@&quot;^(?:I&apos;m on|I go to) the search page$&quot;)]<br />        publicvoidGoToSearchPage()<br />        {<br />            _browser.GoTo(&quot;http://www.google.com/&quot;);<br />        }<br /> [When(&quot;^I search for &quot;(.*)&quot;$&quot;)]<br />        publicvoidSearchFor(string query)<br />        {<br />            _browser.TextField(Find.ByName(&quot;q&quot;)).TypeText(query);<br />            _browser.Button(Find.ByName(&quot;btnG&quot;)).Click();<br />        }<br /> [Then(&quot;^I should be on the search page$&quot;)]<br />        publicvoidIsOnSearchPage()<br />        {<br />            Assert.That(_browser.Title == &quot;Google&quot;);<br />        }<br /> [Then(&quot;^I should see &quot;(.*)&quot; in the results$&quot;)]<br />        publicvoidResultsContain(stringexpectedResult)<br />        {<br />            Assert.That(_browser.ContainsText(expectedResult));<br />        }<br />    }<br />}<br />
  47. Given /^(?:I&apos;m on|I go to) the search page$/ do<br />  visit &apos;http://www.google.com&apos;<br />end<br /> <br />When /^I search for &quot;([^&quot;]*)&quot;$/ do|query|<br />  fill_in &apos;q&apos;, :with =&gt; query<br />  click_button &apos;Google Search&apos;<br />end<br /> <br />Then /^I should be on the search page$/ do<br /> dom.search(&apos;title&apos;).should == &quot;Google&quot;<br />end<br /> <br />Then /^I should see &quot;(.*)&quot; in the results$/ do|text|<br />  response.should contain(text)<br />end<br />
  48. Software<br />Recommended:<br />IronRuby<br />Ruby<br />Cucumber<br />Rspec<br />WebRat<br />mechanize<br />Selenium RC<br />selenium-client<br />Caricature<br />activerecord-sqlserver-adapter<br />Optional:<br />XSP Mono<br />JetBrain’sRubyMine<br />JRuby<br />Capybara<br />Celerity<br />Active record <br />active-record-model-generator<br />Faker<br />Guid<br />
  49. Useful Links<br />http://www.github.com/BenHall<br />http://blog.benhall.me.uk<br />http://stevehodgkiss.com/2009/11/14/using-activerecord-migrator-standalone-with-sqlite-and-sqlserver-on-windows.html<br />http://www.testingaspnet.com<br />http://<br />http://msdn.microsoft.com/en-us/magazine/dd434651.aspx<br />http://msdn.microsoft.com/en-us/magazine/dd453038.aspx<br />http://www.cukes.info<br />
  50. Getting SQL Server to work<br />gem install activerecord-sqlserver-adapter<br />Download dbi-0.2.2.zip <br />Extract dbdADO.rb to rubysite_ruby1.8DBDADO.rb<br />

×