/litmus

a playframework (1.2.x) module that allows for more expressive testing

Primary LanguageJavaApache License 2.0Apache-2.0

Litmus

Litmus is a playframework (1.x) module that makes TDD easier with play. It's main features are:

  • more expressive functional testing
  • easy testing of your model validation, both built-in or custom validations
  • custom test runner that allows you to categorize tests and run categories separately, or to run just the fast tests.
  • selenium WebDriver integration, no more selenium 1

Getting started

To use Litmus, add the following to your dependencies.yml file:

require:
 - litmus -> litmus 0.2.3

repositories:
    - bverbeken:
        type: http
        artifact: "http://bverbeken.github.com/modules/[module]-[revision].zip"
        contains:
            - litmus -> *

After that, a simple play deps --sync should be enough to get you up and running.

Expressive functional testing

For example, litmus allows you to write most of your functional tests as one-liners like these:

assertThat(get("/foo/bar").isUtf8();  
assertThat(get("/foo/bar").hasFlashParam("success");

Model validation testing

Litmus also provides a superclass for model validation tests (thoughtfully called "ValidationTest"), to take away any excuse you might have not to test validation anymore. You can write things like:

assertThat("firstName").isRequired();
assertThat("firstName").shouldNotBe("");
assertThat("houseNumber").withValue(123).isValid();

Custom test runner

When using Litmus, the usual play test runner gets replaced by an alternative version (http://localhost:9000/@tests).

If you annotate your test classes or their superclass like so:

@Category(value = "verySlowTests")

then the litmus test runner will pick up these categories and allow you to run them separately from your browser. Subclasses of litmus.UnitTest, litmus.FunctionalTest or litmus.WebDriverTest are categorized by default as respectively Unit Tests, Functional Tests and WebDriver Tests.

Of course, play auto-test still works as before.

Note: you can disable the alternative test runner by adding litmus.runner=false to your application.conf file.

Documentation

For more information on how to use Litmus, you can refer to

  • the samples folder, which contains a play application that has examples for all the available asserts.
  • the documentation page, which can be found here.

What could be improved/added

  • more asserts (json assert, ..?)
  • other types of testing (javascript unit testing?)

Kudos to the people behind

Project Information

Source code: https://github.com/bverbeken/litmus
Issue tracking: https://github.com/bverbeken/litmus/issues

This is a work in progress (of course it is, it's software).
If litmus is missing features you dream of, or you have suggestions on how it could be made better, tweet me (@bverbeken) or send a pull request.