Some languages offer a very simple syntax for testing via assertion statements, for example with an assert
function that creates a simple test that passes if given a true value and fails for anything else. This style of testing is admirably concise, but can lead to cryptic test messages that make it very difficult to determine what a test was attempting to check without opening up the file containing the failing test. At the other extreme, it's possible to write very expressive tests with a fluent, method-chaining API. For example, using the Chai.js assertion library, a test might read beverages.should.have.property('tea').with.lengthOf(3)
. This allows tests to automatically generate much more useful messages but comes at the cost of creating a fairly complex test API with many new methods to learn.
Raku's core Test module falls somewhere between these two extremes – it offers an API with a handful of functions that's easier to learn than a full fluent API but more expressive than simple assert
statements. This is a sensible compromise.
But I claim (assert?) that, with a bit of metaprogramming trickery, Raku lets us have the best of both worlds: we can have a zero-learning-curve test API that's just as simple as assert statements while also being just as expressive as a long chain of method calls in a fluent style. I'll present this style of testing, discuss its use in Raku, and consider ways in which Raku lets us improve on the status quo.
Speakers: Daniel Sockwell