0
Testing
Why we need to test our code (site)? <ul><li>Ensure security </li></ul><ul><li>Check semantic and syntax </li></ul><ul><li...
Testing types <ul><li>Unit Test </li></ul><ul><li>PHPUnit (PHP) </li></ul><ul><li>SimpleTest (PHP) </li></ul><ul><li>jUnit...
Testing in common use <ul><li>Grouping test suites -> test tree </li></ul><ul><li>     Optional start node </li></ul><ul><...
Testing functions <ul><li>check if on value is... </li></ul><ul><li>     a specific value </li></ul><ul><li>     true </li...
Browser element properties <ul><li>Locators </li></ul><ul><li>     id=___ </li></ul><ul><li>     name=___ </li></ul><ul><l...
UnitTest sample <ul><li>public class UserTest extends UnitTest { </li></ul><ul><li>     private User user; </li></ul><ul><...
Functional test sample <ul><li>public class SearchTest extends FunctionalTest { </li></ul><ul><li>     function testFindRe...
What you can test? <ul><li>Unittest: </li></ul><ul><li>     Levels: </li></ul><ul><li>         Function testing </li></ul>...
Shortcomings in testing <ul><li>Testing GUI appearance </li></ul><ul><li>Complicated system actions (e.g.: in specific cas...
Why TDD is cool? <ul><li>You can fix the topmost (maybe all the) requirements </li></ul><ul><li>Help to build a more stabl...
Drupal and testing <ul><li>Drupal uses SimpleTest framework </li></ul><ul><li>Bunch of helper to ease preparing environmen...
Tips and tricks <ul><li>Try to cover all your code with tests </li></ul><ul><li>Don't write test depend on other tests </l...
Upcoming SlideShare
Loading in...5
×

Testing And Drupal

2,292

Published on

Testing in Drupal

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,292
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
17
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Transcript of "Testing And Drupal"

  1. 1. Testing
  2. 2. Why we need to test our code (site)? <ul><li>Ensure security </li></ul><ul><li>Check semantic and syntax </li></ul><ul><li>In a small team you can track changes </li></ul><ul><li>It can reveal bugs in a very early stage of development </li></ul><ul><li>Environment validation </li></ul><ul><li>Fast </li></ul><ul><li>Permanent (not like us:( ) </li></ul><ul><li>TDD - (later) </li></ul>
  3. 3. Testing types <ul><li>Unit Test </li></ul><ul><li>PHPUnit (PHP) </li></ul><ul><li>SimpleTest (PHP) </li></ul><ul><li>jUnit (Java) </li></ul><ul><li>NUnit (C#) </li></ul><ul><li>... </li></ul><ul><li>Functional Test </li></ul><ul><li>Selenium </li></ul><ul><li>     IDE (html) </li></ul><ul><li>     Grid (???) </li></ul><ul><li>     Remote Control </li></ul><ul><li>     Core </li></ul><ul><li>Castle </li></ul>
  4. 4. Testing in common use <ul><li>Grouping test suites -> test tree </li></ul><ul><li>     Optional start node </li></ul><ul><li>Set-Up <-> Tear-Down </li></ul><ul><li>Every single test could be a separate workflow </li></ul><ul><li>Arbitrary extension capability (SimpleTest -> SimpleBrowserTest) </li></ul><ul><li>Skip tests </li></ul>
  5. 5. Testing functions <ul><li>check if on value is... </li></ul><ul><li>     a specific value </li></ul><ul><li>     true </li></ul><ul><li>     false </li></ul><ul><li>     not null </li></ul><ul><li>     null </li></ul><ul><li>check if an element / object </li></ul><ul><li>     exists </li></ul><ul><li>     not exists </li></ul><ul><li>     equal to ... </li></ul><ul><li>check if an error (exception) occure </li></ul><ul><li>check if an event triggered </li></ul>
  6. 6. Browser element properties <ul><li>Locators </li></ul><ul><li>     id=___ </li></ul><ul><li>     name=___ </li></ul><ul><li>     dom=___ (javascript object) </li></ul><ul><li>     xpath=___ </li></ul><ul><li>     link=___ </li></ul><ul><li>     css=__ </li></ul><ul><li>Matchings </li></ul><ul><li>     glob:___ </li></ul><ul><li>     refexp:___ </li></ul><ul><li>     exact:___  </li></ul>
  7. 7. UnitTest sample <ul><li>public class UserTest extends UnitTest { </li></ul><ul><li>     private User user; </li></ul><ul><li>     void setUp() { </li></ul><ul><li>         this.user = User.GetSampleUser(); </li></ul><ul><li>     } </li></ul><ul><li>     void testUserSetName() { </li></ul><ul><li>         this.user.setName('John Doe'); </li></ul><ul><li>         this.assertTrue(this.user.name.length > 0); </li></ul><ul><li>         this.assertFalse(this.user.name == 'anonym'); </li></ul><ul><li>         this.assertEquals('John Doe', this.user.getName); </li></ul><ul><li>     } </li></ul><ul><li>} </li></ul>
  8. 8. Functional test sample <ul><li>public class SearchTest extends FunctionalTest { </li></ul><ul><li>     function testFindResult() { </li></ul><ul><li>         this.openBrowser('firefox'); </li></ul><ul><li>         this.open('http://www.example.com', 30000); </li></ul><ul><li>         this.type(&quot;//input[@id='search-field']&quot;, &quot;Harrr&quot;); </li></ul><ul><li>         this.click(&quot;//fieldset/input[@type=submit]&quot;); </li></ul><ul><li>         this.waitForPageToLoad(30000); </li></ul><ul><li>         this.assertTestPresent(&quot;regexp:+ results found.*&quot;); </li></ul><ul><li>         this.assertCookieExists('MySessionID'); </li></ul><ul><li>     } </li></ul><ul><li>} </li></ul>
  9. 9. What you can test? <ul><li>Unittest: </li></ul><ul><li>     Levels: </li></ul><ul><li>         Function testing </li></ul><ul><li>         Feature testing </li></ul><ul><li>         System testing </li></ul><ul><li>Functional test: </li></ul><ul><li>     Page elements </li></ul><ul><li>     Ajax jobs </li></ul><ul><li>     Javascript </li></ul>
  10. 10. Shortcomings in testing <ul><li>Testing GUI appearance </li></ul><ul><li>Complicated system actions (e.g.: in specific cases) </li></ul><ul><li>There is no setup and teardown on test suit level </li></ul><ul><li>It's easily became slow </li></ul><ul><li>Browser (un)capabilities </li></ul><ul><li>     frame / window handling </li></ul><ul><li>     security issues (file upload) </li></ul><ul><li>     best in FF (of course) </li></ul><ul><li>If your code needs some conceptual change, likely your tests too </li></ul><ul><li>Selenium sometimes collide with other JS frameworks (MooTools) </li></ul><ul><li>UnitTest modify access to global variables, so sometimes those are unavailable </li></ul>
  11. 11. Why TDD is cool? <ul><li>You can fix the topmost (maybe all the) requirements </li></ul><ul><li>Help to build a more stable software requirement </li></ul><ul><li>Continuous code checking </li></ul><ul><li>Prevent from writing test for code (the best: write code for the test) </li></ul>
  12. 12. Drupal and testing <ul><li>Drupal uses SimpleTest framework </li></ul><ul><li>Bunch of helper to ease preparing environment for test for: </li></ul><ul><li>    create user  </li></ul><ul><li>    login user </li></ul><ul><li>    post node </li></ul><ul><li>Every core module has it's own module.test file </li></ul><ul><li>Every core.inc has it's own test in simpletest module </li></ul><ul><li>Unfortunately Drupal's Selenium module is unsupported now </li></ul>
  13. 13. Tips and tricks <ul><li>Try to cover all your code with tests </li></ul><ul><li>Don't write test depend on other tests </li></ul><ul><li>    If one fails, it can ruin other tests (even good ones) </li></ul><ul><li>    Without dependency, every test could be called separately </li></ul><ul><li>Never run tests on live site (neither live database dump) </li></ul><ul><li>You can write a script to svn that runs the test suit before commit - prevent from commiting false code </li></ul>
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×