Search code examples
unit-testingqunitautobahnwamp-protocol

How to test WAMP-Services?


Context: i want to write a web service that uses WAMP (Web Application Messaging Protocol, not the Service-Collection for Windows). WAMP should be used since it supports Events and RPC in a quite easy way. And with lower overhead.

Now how can i unit-test the RPC-methods of my service without writing everything by hand?

My first approach was taking Autobahn-JS and QUnit together. The problem here was that AutobahnJS does not support a blocking "open()" method. So i can't be sure that the connection that gets opened by QUnits beforeEach-hook. See this example:

var connection;

QUnit.module("Module 1", function(hooks) {    
    hooks.beforeEach(function(assert) {
        // insert something executed before each test
        connection = new autobahn.Connection({
            url: wstarget,
            realm: wsrealm
        });
        connection.open();
    });

    QUnit.test( "check something", function( assert ) {
        assert.ok(connection.isConnected == true);
        // do something here that requires open connection...
    }); 
});

Are there other/better options?


Solution

  • Solution by a co-worker:

    QUnit offers a method to allow asynchronous tests. It's usage is a bit like commiting a database transaction. I had to set, i'm expecting a callback with

    var asyncOp = assert.async();
    

    and "commit" it with

    asyncOp();
    

    inside the callback.

    Source: https://api.qunitjs.com/async/