The Grinder 3.6 and later optionally support Clojure as an alternative language for test scripts.

How to use Clojure

Install Clojure and add the path to the installation's clojure-x.x.x.jar file to the start of the CLASSPATH you use for The Grinder agent processes.

Clojure scripting

Script structure

Clojure scripts must conform to a few conventions in order to work with The Grinder framework.

  1. Scripts must return a function that creates test runner functions

    When a worker process starts, it runs the test script once. The test script should return a factory function that creates and returns a test runner function.

    Each worker thread calls the factory function to create a test runner function. Worker threads perform a number of runs of the test script, as configured by the property grinder.runs. For each run, the worker thread calls its test runner function; thus the test runner function can be thought of as the definition of a run.

  2. The test script can access services through the grinder object

    The engine makes an object called grinder available for the script to import. It can also be imported by any modules that the script calls. This is an instance of the Grinder.ScriptContext class and provides access to context information (such as the worker thread ID) and services (such as logging and statistics).

  3. The script file name must end in .clj

    The file name suffix is used to identify Clojure scripts.

Canonical test script structure

This is an example of a script that conforms to the rules above. It doesn't do very much - every run will log Hello World to the output log.

;; helloworld.clj
(let [grinder net.grinder.script.Grinder/grinder]

  ;; The script returns a factory function, called once by each worker
  ;; thread.
  (fn []

    ;; The factory function returns test runner function.
    (fn []	
        (.. grinder (getLogger) (info "Hello World"))))))

Recording an HTTP script

You can use the TCPProxy to record a Clojure script from a browser session.