Spek – A Specification Framework

Hadi Hariri

For a while now, a few of us have been working on a project called Spek, a framework that allows you to write executable specifications. It allows you to write specifications (i.e. tests) in a more human-readable, and what’s more important, descriptive manner, without having to resort to long test names, underscores or regular expressions.

It’s now reached its first milestone where it’s suitable enough to start being used on projects and we’re ready for feedback and feature requests! It even has its own site.

A brief introduction

Spek is a Specification Framework. If you’re familiar with Jasmine, Mocha, RSpec or Machine Specifications, then you’ll immediately see the resemblance.

image

If you’re not familiar, let me briefly explain:

  • Given – Establish the context of the test, i.e, Arrange
  • On – Execute the action, i.e. Act
  • It – Validate the results, i.e. Assert

Spek allows you to have more than one action for the same context. That is for the same given you can have multiple on’s. It also allows you to have more than assertion (it) for the same action.

Spek is not only for Kotlin

Spek is written in Kotlin. Specifications you write will also be in Kotlin. However, as Kotlin is 100% compatible with Java, you can test new and existing Java code with Spek.

How do I run it?

IntelliJ IDEA supports Spek, so does TeamCity. There’s also a console runner which outputs Text and HTML (needs improvement).

image

Try it

Hoping that you like what you see, head over to the Spek web site to find out more. It’s still in “EAP” so the more issues reported, the better. And since it’s OSS (Apache 2) contributions are more than welcome.