Help the suits write functional tests for Angular apps with Cucumber
You might call this Acceptance Test-Driven Development...
No matter what the fate of the AngularJS Web development framework may be in the near future, the fact of the matter is it's here now and many enterprises have, surprisingly, began to adopt it. As such, it is increasingly important to unify the set of tests that developers care about with the set of tests that business people care about (and that the QA automation team really likes to code the most). This is hard because while the QA team can go on and write their own scripts to their heart's content, the business folks really can't do the same thing -- they lack the time and/or the technical inclination. Thus, the automation team should be responsible for helping out the business folks by providing a "common language" (ideally, a specific subset of English words) so that everyone can describe tests for a system regardless of their know-how.
What have I experienced so far in ATDD?
Thus far, I am familiar with two such systems -- Robot Framework, and Cucumber. Both of these tools employ keywords (which usually people construct from English phrases) with which people can describe tests. Both are simply layers above real code you write in a language of your choice (Ruby, JavaScript, Python, etc.) However, Cucumber can take things a step further than I've seen people do with Robot: your keywords can include regular expressions. (This isn't huge, since keyword arguments can do the same thing in Robot.) The difference would look something like this:
Cucumber: When I go to http://mysite.com
Robot: Go To Website http://mysite.com
In Robot scripts, you can plop in entire data structures as arguments to a keyword. This might blow the minds of some people from the business side, so I haven't seen a direct corollary to this in Cucumber (which, for some reason, you don't really write "Cucumber", you write "Gherkin" syntax -- a type of cucumber, haha). On the other hand, Cucumber does allow you to write repetition in an interesting manner. Imagine you have a table of data representing inputs and outputs for identical operations that should be run on a particular row of data: the syntax described here allows you to run it without needing to understand anything about loops or indexes.
Robot has a plethora of built-in keywords and additional libraries that provide all sorts of functionality without requiring you to write code in the underlying language. When I was working with Robot, it was layered on top of modules we wrote in Python. I and many others on my team would choose to write new keywords using existing Robot keywords in order to avoid modifying the keyword file plus Python code and other libraries. However, some of these built-in keywords are very tedious to use (Heaven help you if you want to do complex logic in Robot, for instance), and you can end up being led down a rabbit hole fairly fast if you have this mindset. With Cucumber, you avoid rabbit holes because everything must be written in the underlying language. Despite that this requires more files to get reviewed before check-in, I actually prefer this because as long as you like the underlying language (Python, JavaScript, etc.), it's generally more pleasant to work with than a limited set of keywords and operators.
Finally, Robot reads to me more like some old-time procedural language like BASIC, whereas Cucumber Gherkin reads more like a true outline for an acceptance test. Gherkin statements always begin with "Given", "When", or "Then", and a whole test only contains these types of statements. Robot code could read in a similar manner if you have created layers of keywords that abstract such given/when/then test requirement elements from any underlying operations (e.g. opening a webpage or file, comparing data, or doing arithmetic), but in my day-to-day role as a Robot & Python test developer, the stuff I wrote never quite read like Gherkin, but the stuff that the "suitesmith" made probably did.
I didn't really intend to even bring Robot into this post at all, but figured it couldn't hurt. :-P This is definitely not guaranteed to be an exhaustive analysis of Robot vs. Cucumber, but will get you the salient points from my own experience.
Comments
Post a Comment