Front-end testing: Mink integration now available in 5.34

Közzétéve
2021-02-04 06:46
Written by
DaveD - member of the CiviCRM community - view blog guidelines

Thanks to some work by MGlaman and KarinG and others, some integration with the Mink/Behat front-end testing framework is now available for you to use to write automated tests. Does it replace regular phpunit? No, you should still write regular tests too. But let's take a look at what it can add.

What are front-end tests? They're tests that automate controlling a browser to fill out fields and click on buttons, as opposed to the usual back-end tests that might check the output of a function.

Why Mink? Several of the other front-end frameworks only run client-side, which means that you're limited to testing and asserting what's visibly available in the browser. For example you can't assert against the results that get stored in the database unless there's a web page you can navigate to that shows that or an ajax call available to get at the values. With this framework, you have both at the same time. You can mix all the usual php calls in between the steps that click on things. Let's look at a chart:

FeatureMinkNot Mink
Call backend PHP code and click on things?Yes √Probably not

Ok that wasn't much of a chart, but in fairness charts are hard.

A second answer to "why mink?" is that a lot of the groundwork to integrate it with the CMS has already been done in the Drupal 8 world. But don't be scared by the mention of Drupal 8 - to use this framework you don't need to know much about Drupal or need to administer a Drupal site. It's just that the Civi integration builds on top of what's already been done elsewhere. So yes there will be Drupal 8 files that sit on your computer. Who's to say that wouldn't have happened randomly anyway if you looked away from the screen for long enough? Crazier things have happened recently.

Want to give it a try? There is some documentation in the developer guide at Mink Testing which you can follow through to get started, and at the bottom of that page you'll find some more links for further exploration. There is also a sample extension you can use as a base for your tests.

Filed under

Comments

Awesome work, thanks for taking the time to post as News and thanks to everyone that contributed! :)

Great to hear about this! To be clear, is Mink only meant to test Civi-D8 sites? Does it not work with WordPress or any other CMS?