4

JsonLogic is a data format (built on top of JSON) for storing and sharing rules between front-end and back-end code. It's essential that the same rule returns the same result whether executed by the JavaScript client or the PHP client.

Currently the JavaScript client has tests in QUnit, and the PHP client has tests in PHPunit. The vast majority of tests are "given these inputs (rule and data), assert the output equals the expected result."

As the test set grows (and certainly as we add parsers in other languages) how can we maintain just one standard set of test data and expected results that each get executed in each language's testing framework?

Jeremy Wadhams
  • 201
  • 1
  • 7

1 Answers1

5

A simple approach would be to just write one JSON file like:

[
    [ rule, data, expected ],
    [ rule, data, expected ]
]

And then in each language, download the file, parse it, and test it, row by row.

My first inclination was to use a CSV (I'm back now to edit that answer), but as soon as the test data includes objects and arrays, suddenly you have a CSV with JSON in the cells, and it becomes eye-stabbingly frustrating to maintain.

Jeremy Wadhams
  • 201
  • 1
  • 7
  • The [Cucumber](https://cucumber.io/) test framework for Ruby propagates something like this – write your tests in a natural language that's close to the domain, and then write a few lines of glue code to make them executable. This is also an excellent strategy to make your tests language independent. – amon Oct 28 '15 at 19:49