Using cucumber as a DSL for business rules?

446 views
Skip to first unread message

Tom Eugelink

unread,
May 18, 2016, 7:56:38 AM5/18/16
to Cukes
Some years ago I have written a price logic using mini expressions and then creating javascript in Java to evaluate. For example in a column "amount" one could type ">100" and in the price column "10", meaning that if you sell more than 100 units, the unit price would become 10 dollars. I would generate javascript in the form of "if (amount > 100) return 10" en execute that dynamically. Works fine and the flexibility is very appreciated by the users.

Now I need to do something similar and am considering using Gherkin:
    When amount > 100
    Then unit price is 10 USD

So not asserting business rules, but actually writing them in Gherkin. Has anyone tried this before?

What is the appropriate class to use in Cucumber-JVM to manually run such features?

Tim Walker

unread,
May 18, 2016, 8:19:28 AM5/18/16
to cu...@googlegroups.com
Replied inline below...

Hi Tom, what you've described is at the very heart of Cucumber though it's the discussion which arrived at these business rules which is paramount in BDD (Specification by Example). These features are easily run in Cucumber-JVM, either from the command line, Maven/Gradle or the IDE. There are exceptional resources and videos available to get you started. When you run these features each of the steps is matched to "glue code" using a regular expression for matching, supporting your syntax and providing variables. From the glue code to can test your System Under Test directly using the classes involved, or through the UI (if the rule is a UI rule, business rules should not go through the UI as a general rule). I'd look at the Cucumber Book for Java as well as the Videos in You Tube and Gojko Adzic's "Bridging the Communication Gap" and "Specification by Example".  Hopefully this helps you get started. 
--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Roberto Lo Giacco

unread,
May 27, 2016, 6:41:32 AM5/27/16
to Cukes
I don't think Cucumber will be of much help here, other than for inspecting how it uses Gherkin. Luckily for you Gherkin is a separate project/jar, which means you can use it separately from Cucumber.

I personally had your same requirement a few years ago (it was a pricing system for mobile telco), but I used Drools for it (as it has support for DSLs). 

I personally don't think Gherkin is fit for the purpose as the language has no support for looping or aggregation, operations you might need to have to sum up or inspect the details of an order....

have fun!
Reply all
Reply to author
Forward
0 new messages