Drupalcamp Simpletest

Post on 13-May-2015

1.390 views 1 download

Tags:

Transcript of Drupalcamp Simpletest

Testing in DrupalAn Introduction

Who Am I?

Simon RobertsIT Consultant,Taniwha SolutionsUsing PHP since ~1996Using Drupal since 2005http://drupal.org/user/33667

First used SimpleTest at Drupalcon Szeged Testing Sprint

Who Am I?

Before the Drupalcon, I’d only had the most casual of looks at Testing in DrupalHave used JUnit etc previouslyWas able to provide useful tests to Drupal Core inside a couple of hours!!You can too!

What was SimpleTest?

PHP Testing FrameworkIntegrated as a contributed module in D5 + D6Integrated in core for Drupal 7 (sortof)Implements Automated Testing

Why Automated Testing?

Define exactly what the code should do Easier development Easier to refactor code Less debugging Less mistakes More fun!!

Why Automated Testing?

Document Bugs$xss = '<script>alert("xss")</script>'; $edit = array(

'title' => $xss,

);

$node = $this->drupalCreateNode($edit);

$this->drupalGet('node/' . $node->nid . '/edit');

$this->assertNoRaw($xss, t('Harmful tags are escaped.'));

Why Automated Testing?

Document BugsPrevent regressionsQuality AssuranceBetter Software

Safety net!

Why Automated Testing?

Once a test is written, it will likely be run many many timesEvery time it is run, it verifies that the code is still workingIf it catches even one bug, it has “paid for itself” - High valueCan be used to help reproduce problems

Testing in Drupal Core

Dries (and Drupal!) has made Testing a high priority for Drupal 7http://buytaert.net/drupal-7-timeline

Effective Test coverage allows us to compress the “fix” phase of a Drupal release (code freeze)

The actual Drupal 6 Timeline

The Drupal 7 timeline assuming that we fully embrace testing.

Note: These dates are going to be delayed anyway - slower migration to Drupal 6 than expected (eg: CCK, Views, Panels. drupal.org)

Not just for Drupal Core!

so... how does it work?

.test files

Contain test classes

Test classes extend the SimpleTest class

well, not exactly

Use Helper methods to:

Simulate user actions

Check behavior

No, really... how does it work?

Let me show you...

What’s Left To Do?

Outstanding Testing Issueshttp://drupal.org/project/issues?projects=3060&versions=156281&components=simpletest.module,tests

“We currently have 38 tests taken out of 43 for a test coverage of 88%. This will change when the misnamed tests are merged.” http://groups.drupal.org/node/9408

References

Webchick’s presentation “Testing Part 1: Intro to Testing” (Szeged Drupalcon)

http://drupal.org/simpletest

http://groups.drupal.org/testing-qa

One SimpleTest template to rule them allhttp://groups.drupal.org/node/7731

Drupal testing patternshttp://groups.drupal.org/node/15190