Testing And Drupal
Upcoming SlideShare
Loading in...5
×
 

Testing And Drupal

on

  • 3,497 views

Testing in Drupal

Testing in Drupal

Statistics

Views

Total Views
3,497
Views on SlideShare
3,488
Embed Views
9

Actions

Likes
2
Downloads
16
Comments
0

3 Embeds 9

http://www.slideshare.net 7
http://www.linkedin.com 1
https://www.linkedin.com 1

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Testing And Drupal Testing And Drupal Presentation Transcript

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