Client side test in Drupal -- let's figure this out

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
jessebeach's picture

Much of our front end testing effort has gone into the TestSwarm module (the platform) and the Frontend Automated Tests module (the tests).

Having written several tests now, I've come to the following conclusions:

  • We have better tools at our potential disposal to allow non-technical folks (UX, documentation, etc) to define what behaviors they expect from a feature; later a technical person can translate this description in to tests.
  • QUnit, the framework we're using now, has bad support for asynchronous tests. The syntax quickly becomes unruly and verbose. A framework like Jasmine has much better support for asynchronous functionality.

Below are some links about discussions that have already happened. I'm sure there are more links I could add here regarding what others have said about front end testing in Drupal. Please add additional links in comments if you think they are relevant.

DrupalCon Portland 2013: AUTOMATED TESTING WITH JASMINE AND PHANTOMJS

DrupalCon Prague 2013 :JAVASCRIPT TESTING

Next Steps

I would like us to come to conclusion on the following questions:

  1. What framework should we use for behavior driven development?
  2. Is there a common syntax across BDD frameworks that would allow us to start writing descriptions of feature behavior prior to picking a framework?
  3. What framework should we use for writing assertions?
  4. Is our QUnit/TestSwarm combo good enough for our needs? Have you personally had success with this combo?

Comments

I believe JS testing was

chx's picture

I believe JS testing was discussed at DC SF some 3.5 years ago and we were thinking that we would ask people to point their browsers to a swarm page and so we can test with real browsers for free. This doesn't require money or knowledge from contributors so it could become a very easy way to contribute.

:-)

As If's picture

CrowdSwarming. Nice.

Chx linked me to this page in

jessebeach's picture

Chx linked me to this page in chat, a recap of DrupalCon San Francisco: http://marvil07.net/blog/2010/drupalcon-san-francisco-2010-or-why-i-love...

which lead me to this issue that I hadn't known about before about establishing a front end testing framework: https://drupal.org/node/237566

What I would really really

jessebeach's picture

What I would really really really like to hear from folks in the community is their success or failure stories employing various combos of tools.

via @seutje Google's

jessebeach's picture

via @seutje

Google's migration to Selenium 2.0

https://www.youtube.com/watch?v=cSLmfegT36A

My impressions regarding Front-end Automated Testing

rteijeiro's picture

Hi, after speaking about Front-end Automated Testing in a few Drupalcamps around Europe, I had the opportunity to discuss with several Drupal folks about their solutions for front-end testing:

  • The most used framework is Selenium but it's not a front-end specific testing framework. As well is difficult to setup and configure for front-end developers so I would not consider it as a solution.

  • Mostly commonly used framework is CasperJS. I can say that it's a powerful front-end testing framework and, in combination with PhantomJS, it could fit in most common environments. I have also tried DalekJS that, despite being so new, it seems to will be a good framework in a future.

@jessebeach, answering your questions:

  1. Jasmine.
  2. There is no standard but I think something like Gherkin could fit our needs: https://github.com/cucumber/cucumber/wiki/Gherkin
  3. My experience is that QUnit fits my expectations in most common scenarios. But, if we want a solution for Drupal 8, maybe we should consider also testing frameworks for Backbone like http://backbone-testing.com
  4. Definitely sure. It fix really well with jQuery and javascript code in Drupal, as far as I tested it.

We can discuss this longer if you want. I think we need to spend some time looking for a good solution for our needs.

Calm Down & Clear the Cache

More resources

vladan.me's picture

I have to agree with @rteijeiro, moreover I really like and recommend this presentation:
http://www.slideshare.net/Phase2Technology/testing-withghostsandgherkins

CasperJS seems like a very nice solution. Syntax-wise looks like traditional SimpleTest framework (asserts and similar) and is also JavaScript friendly, you can even use jQuery if you are not familiar with classic selectors provided for interaction with DOM. I mean, I feel that it may be well adopted if chosen as a solution. DalekJS mentioned I have never tried but seems like a very young project, need to be monitored but certainly not to be used right now.
On other hand, about Jasmine, syntax is bit strange, no (e.g. spies. mocking?!), I have never tried, is just first look, not sure about usage. Can't all that functionality be replaced with only CasperJS or I am missing something?

vladan.me, rteijeiro, it

jessebeach's picture

vladan.me, rteijeiro, it seems like could start writing feature description in Gherkin now.

https://github.com/cucumber/cucumber/wiki/Gherkin

And this wouldn't limit us in terms of the assertion library we use down the line.

Thoughts?