logo
logo
Sign in

Automating functional test with Behat and Drupal: Cón and start-up from scratch

avatar
Knox Norris


¿Qué is Behat?


Behat is a tool
BDD(Behaviour Driven Development) that is used to verify the behavior of an applicationón from the point of view of an end. It is very popular to use this tool for testing automatización of cases, using scenarios intelligible to the human.


To edit the test using the language, very akin to the Englishés, so that they can write the tests of the form "Taking into account that... Then dutyíto...". Can además extended by writing PHP functions tailored to a file FeatureContest.php that is created in the carpetita bootstrap.




¿When using Behat?


Behat help to meet the specifications and requirements of the client of the service since it launched with
testthat describe scenarios of possible behavior of the user in the web page. These tests can be created and maintained by any person, whether you are a project manager, a developer or any other party interested in the project.



test automatedBehat can help:



¿Where you can't help Behat?



  • Check data dinámicos.

  • Processes on imágenes.

  • Cócodes of response links of a site.


hereón we pass to the phase of facilityón, in order to run Behat in our Drupal Trademark from zero.



Cón


You can install so cófashionable and easy through
< budget online store zamora . Add these lines to your composer.json in Drupal, or, in a carpetita /behat apart.


Then we let composer do its work:


$ composer install


Afterés of this, we will have new carpetitas as:


/bin (Where está the executable behat and others like drush)


/vendor (all dependencies are accurate)


Now we need this other file:



behat.yml


Remember to alter the url that you want to test in: base_url.


Then:


$ bin/behat --init


And the final step:


us dollars bin/behat -dl


This list shows the possible actions that we can use in the test, and their syntax.



by Writing our first test. Scenarios


The scenarios describe the functionality you wish to test, as if it were an end-user. These scenarios are written in files called fueatures and stay on the carpetita /features.



Example, we want to test that a user wónimo Drupal Trademark, you can start and close properly your sesión. In the front we have enabled a block that sówhat you seeán registered users, with a text "Welcome to user". The user anónimo should notísee that block, nor the tools.


Create a new file in /features:


home.feature


Now, we launched the test, from the root of the project


us dollars bin/behat


As we can see, the stage is válido and validates the test complete without errors (11 steps / eleven passed).


Suppose that you accidentally change the settingón of the block, and is visible alsoén for users wóminimum, we launched again the test, and showíto the following:


And ahí we have noticeable the fault, identified perfectly with the scenario.



Conclusions



This tooltherefore
help to adopt best prápracticesin the development teams, being very advisable routine to run the tests before sending a commit, to make sure that the cóI say it does not produce regressions, even your integratingón with tools integrationón continuous as a
Jenkins.

collect
0
avatar
Knox Norris
guide
Zupyak is the world’s largest content marketing community, with over 400 000 members and 3 million articles. Explore and get your content discovered.
Read more