Skip to content

Instantly share code, notes, and snippets.

@colaru
Created August 21, 2013 10:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save colaru/6292618 to your computer and use it in GitHub Desktop.
Save colaru/6292618 to your computer and use it in GitHub Desktop.
javascript integration test with module start
/*
* Example JavaScript integration test that deploys the module that this project builds.
*
* Quite often in integration tests you want to deploy the same module for all tests and you don't want tests
* to start before the module has been deployed.
*
* This test demonstrates how to do that.
*/
load("util.js");
var container = require("vertx/container");
var vertx = require("vertx");
var vertxTests = require("vertx_tests");
var vassert = require("vertx_assert");
var console = require('vertx/console')
// The test methods must begin with "test"
function testSendMessage() {
vertx.eventBus.send("$lee-test", UTIL.createMessage ("$lee-test", "$colaru-test", { _t: "req1" }), function(reply) {
console.log('I received a reply ' + reply);
vassert.assertEquals("$colaru-test", reply.header.from);
/*
If we get here, the test is complete
You must always call `testComplete()` at the end. Remember that testing is *asynchronous* so
we cannot assume the test is complete by the time the test method has finished executing like
in standard synchronous tests
*/
vassert.testComplete();
});
}
function testSomethingElse() {
vassert.assertEquals("foo", "foo")
vassert.testComplete()
}
var script = this;
// The script is execute for each test, so this will deploy the module for each one
// Deploy the module - the System property `vertx.modulename` will contain the name of the module so you
// don't have to hardecode it in your tests
container.deployModule(java.lang.System.getProperty("vertx.modulename"), function(err, depID) {
// Deployment is asynchronous and this this handler will be called when it's complete (or failed)
vassert.assertNull(err);
// If deployed correctly then start the tests!
vertxTests.startTests(script);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment