-
Notifications
You must be signed in to change notification settings - Fork 133
Add support for Behat #528
Comments
@pfrenssen, do you happen to have some Behat context extensions of Drupal\DrupalExtension\Context\RawDrupalContext laying around? |
We used a context/trait inspired by https://github.com/ec-europa/joinup-dev/tree/develop/tests/src/ in our project a while ago. Hope it helps |
Thanks for the input @zerolab! We're using similar classes but I didn't find any specific Drupal contexts for Organic Groups. I'm looking for something like:
|
Ah, I see. Here's our subcontext, OgTrait and behat feature - https://gist.github.com/zerolab/96ab2e3044fd3243a7094a90626d479e |
I like this idea! I am also involved with the Behat Drupal Extension project so I welcome this. The Joinup project linked above is indeed a good source of inspiration. This project uses two group types: one is called "collections" and one called "solutions". Here are the subcontexts for both:
It uses a trait called You can see in here typical steps like:
In Behat it is always important to allow users to write their own steps easily, so we should split off as much code as possible to a reusable trait. We do not know the business language preferred by our users, so we can only provide steps like As you see in the examples from the Joinup project they use their own business language. They do not even have the word "group" anywhere, since their clients do not know we are using a Drupal module for this that is called "Organic Groups". For their clients the correct terminology is "collections" and "solutions". We should avoid falling in the trap of using machine names of entity types and bundles, because this results in step definitions which violate the basic principles of BDD. We should do a lookup of the human readable bundle names and use these. And avoid the use of entity types entirely. It would be bad to have a step definition reading I think maybe the best approach would be to provide a trait and some example code that people can adapt to their use case. I followed this approach in https://github.com/drupaltest/behat-traits/ - this project provides reusable traits as the deliverable, but it also provides example Contexts which can be extended (or used directly, if a project has simple requirements). So basically, I would go with a trait and an example context which we can use ourselves for testing that the Behat code works correctly, and can be used by developers as an example, or directly if they have simple requirements. Let's avoid using a subcontext for now. |
Seeing the comment from @zerolab above I think it is significant they also do not use the word "group" in their steps, in their business language a group is called a "network". This shows correct usage of BDD principles of using the client's business language in Behat scenarios. I think this reinforces my idea that we should not try to provide step definitions that are supposed to work out-of-the-box (i.e. a subcontext). It won't be so useful, every project has their own terminology. |
Is there an advantage to this over functional testing? |
Behat is not intended for testing, but it is a tool that describes the end user functionality of a project to the business that owns the project. It can be used as a very cheap way to test UIs, but that is a side effect :) So we should not use it ourselves to test our functionality, but we can make it easy for people to use Behat to demonstrate the projects they build to the business stakeholders. |
Actually it wouldn't be a bad idea to provide Behat scenarios ourselves to demonstrate how to set up some typical scenarios using groups and group content 🤔 People have historically struggled a lot with OG's UI, so having some Behat scenarios that show it step by step could be very helpful for site builders 🤔 |
Ok, I thought the issue was about having the tests for OG using. I used to be a big fan of Behat, but now days I feel it can be easily abused.
I personally think documentation would be better. |
In order to write Behat test for Organic Groups, we'd need some "Gherkin" Drupal contexts for the custom entities that OG is providing (e.g. OgMembership, OgMembershipType, OgRole).
These contexts are really specific for Og and I wonder if we could provide them here, either as snippets/documentation or as real Context in the sourcecode?
On the other hand, there's work being done to allow the creation of custom entities (other than, node, user & term) in jhedstrom/drupalextension#300. This could provide a way forward too.
I'd be happy to get some intput in this.
The text was updated successfully, but these errors were encountered: