Skip to content

ql unit cooked tests

mtipnis edited this page May 2, 2012 · 3 revisions

We have another approach to use ql-unit which involves giving a cooked structure having mock response, test case, setup, teardown, etc. This eliminates the need to use multiple files.

Here is how the structure looks like:

Structure for cooked

    {
        test1:  {  
                   // for mock servers .. different mocks run on different ports

                    ports: [
                        {
                            port: 3026,
                            status: 200,
                            type: "application",
                            subType: "json"
                            payload: '{ "a" : "Value of a", "b": "Value of b"}
                        }
                    ],

                    // Present only for testing scripts not present for route
                    script: "select * from some_table",

                    // Present for routes
                    request: "/myapi",
                    verb: "get",

                    // for routes .. where headers are required
                    headers: {
                        "x-ebay-soa-appname": "avalidappid"
                    }

                    // incase of request payload for routes
                    type: 'application',

                    subType: 'json',

                    payload: '{"a":"abcd"}'

                    // user defined functions for setup/teardown/test .. not mandatory
                    udf: {
                        setup: function (cb) {
                           var ctx = {};
                            ... do something .. likely set ctx
                            someInternalAsyncCall(function(){
                              ... do your things ...
                              cb(ctx);
                            });
                        },
                        test : function (test, err, result, ctx) { // ctx is the one passed by setup
                            test.ok(result, "No result found");
                            test.ok(!err, "Error found");
                        },
                         tearDown : function(cb, ctx){
                            .. doe some clean up .. hint: use ctx
                            cb();
                        }
                    }
                }
    }

For example to use this format check tests-precooked-test

Clone this wiki locally