Getting going with Drupal + PHPUnit + Selenium Web Driver + PHPStorm IDE

Portland ME - Testing is very difficult. Its a pain in the butt but it's one of those neccessary evils. The more websites we build and the increasing number of web application we work on has pushed up to grow in our testing techniques. In the past testing was a final phase of a project where staff members would all hammer on the application with less than well written user stories. To be honest, the fatique of the project along with the fact that the user stories were written only weeks early proved to be an unreliable way to test applications. When the projects were small and the application not as robust, we got away with this process. However as the complexity grew we needed to advance our methodology about testing.

So lets put our adult pants on and step up our game as proffecient developers. As my dad always said, "Perfect practice makes perfect". We need to be thinking testing while we are developing, not after. If we can not get the client to sit down for 4 hours and discover all the user story lines that will be needed for UAT than us developers need to create them as we build. Obviously we are building functionality, we can at least create the stories as we create the functionality. And lets blow our project managers mind and build our Unit Tests at the same time. Typing our user stories is not fun, but creating tests with PHPUnit and Selenium Web Drive is!

If you are a solo developer developing locally all you really need is PHPUnit and Selenium Web Drive. If you are work on a larger team or your project requires robust cross browser support, its worth looking at Sauce Labs. What are all these technologies? PHPUnit is a unit testing framework for the PHP. For example, you want to know that a user can login to the application successfully, or you want to ensure that the user can get through all the steps of a user story line, you need to write a test. PHPUnit provides useful classes and functions to simulate a user preforming these actions. By itself PHPUnit provides tools to create test that are executed at the codebase level. In terms of working with Drupal that means your test will use the Drupal API to execute functionality. For example, your test might programmatically create a node, check the database to ensure one of your node_hooks ran and then delete the node. This type of test is great, especially when you do have a large chain of triggers that you need to ensure are working in harmony. However when we start extending functionality out to the User Interface, PHPUnit alone is not equiped to handle all the different browser anomolies. This is where Selenium comes in to save the day. Selenium has two flavors that I know of. The first one I used was the Selenium IDE for Firefox. It is basically a recording tool that captures every human interaction with your application. From click buttons to typing in form fields, it records the actions so that they can be played back. During play back it will report if the same action was successful or not. For us early on in our testing, the was incredibly useful because it allowed our project manager to tell developers exactly what didnt work. It also saved a lot of time because project managers could build the test since the IDE interface is really easy to use and it made the test repeatable. When outgrow this when test got to be too complicated for the IDE. Bear in mind the IDE is powerful by itself and you can even manually write the file it using to add more complicated steps. The file it uses is HTML and javascript so lower level developers can handle it.

Along with complexity, we still faced that pesky issue of project fatigue and unreliable story lines. It makes more sense for the developers to create the test while the building process is going on. But the test need to be project manager friendly. This is where Selenium Web Drive comes in handy. As coders, developers can write PHPUnit test but still take advantage of all the user interaction tools of Selenium as well as the visual playback of the test. And because we are writing the test at the code level, we have the power of PHP to handle complex interactions. With developers writing the tests it keeps developers focused on the story lines and provides a mechanism for developers to express to project managers how the user will interact with the functionality. Inheritantly it allows project managers and clients to push back on that interaction, but again, with a visual test developers and project managers are speaking the same language. This brings me back to Sauce Labs. If developers are using their local machine to write and run the test, how are the project managers going to see them? Well, hundling around the lap is an options, or we can make sure the tests are checked into the repo and project managers know how run the tests from the command line. Well, I know plenty of project managers that hate the command line, so that might not work for everyone. Sauce Labs provides the solutions with an awesome user interface to view test and get reports on pass and failures. Developers can write their tests locally and run them on Sauce Labs from their command line. The test is actual run on Sauce Labs infrastructure and even video recorded. Project managers can view the test that run on the Sauce Labs website and even playback the test. A beatiful centralize place for developers and project manager to live in harmony knowing they are delivering a functionality product to their client.

At the end of projects, it common to forget why functionality was created and what the requirements were. We would all like to believe our project discovery and architecture documentation can deliver us from the evil of scope creep but lets face it, projects are wild fungus' that strive to strangle us. Writing test while building functionality is just another tool we can look back on at the end of the project and keep those requirements in focus while we are creating.

I would highly suggest watching by Jeffrey Way to get going. Nike Air Max

Comments (0)

About Us

We are web developers versed in front and back end technologies. We like PHP, Drupal and Wordpress for our web apps and Foundation, Bootstrap, SUSY and Sass for our User Interfaces. Contact us to be apart of your next web project.

Latest Articles

Copyright © 2021 Focal55 Inc. / All rights reserved.