logo
logo
Sign in

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

avatar
Stampe Lorentzen


¿Qué is Behat?


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


To write the test employs the language, very similar to the Englés, so I can write the test the way "Taking into account that... Then dutyíto...". Can además extend it by writing functions custom PHP in the file FeatureContest.php that is created within the carpetita bootstrap.




¿When using Behat?


Behat help to meet the specifications and requirements of the user for up to
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 may attend:



  • Verify data and content estático in a web.

  • create an online store , links, and fields.

  • Check forms.

  • Check Workflows as records or purchasing processes.

  • Verify that there are no regressions in the cóI say.


¿Where you cannot attend Behat?



  • Check data dinámicos.

  • Processes on imágenes.

  • Cócodes of response links of a web site.


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



Cón


You can install so cófashion and simple through
composer. Add these lines to your composer.json in the Drupal Trademark, or, in a carpetita /behat apart.


Then we let composer do its work:


us dollars composer install


Afterés of this, we're going to have new folders like:


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


/vendor (all and each of the dependencies to be precise)


Now we need this other file:



behat.yml


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


Then:


us dollars 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, such as if it were an end-user. These scenarios are written in a file 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 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 web design for lawyers , 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 (eleven steps / 11 passed).


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


And ahí we have noticeable the fault, identified at the perfection stage.



Conclusions



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

collect
0
avatar
Stampe Lorentzen
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