Skip to content
rgwch edited this page Apr 24, 2015 · 16 revisions

As a project grows, testing becomes more and more important. In Webelexis, we use the following tools:

Client side

  • karma as a test runner.
  • Mocha as a test framework.
  • Chai as assertion library
  • Sinon for stubs, mocks and spies
  • PhantomJS or Chrome as test environments. PhantomJS is needed for headless development and testing.

Diskussion of these tools would be beyond the scope of this text. Here just a description of the setup:

Most of the tools are listed in the devDependenciessection of package.json. Therefore all are installed, if you simply type npm install from the webelexis-base directory. You can make life a bit easier, if you add manually npm install -g karma-cli (sudo npm install -g kama-cli on Linuxes).

run the test environment with

karma start karma_cfg.js

and run the test suite with

karma run (from a different console)

All javascript tests are located in src/test/resources/web

note: tests can only run after npm build-clientsince tests work on release files.

  • To run Tests within a continuous integration suite, see here as an example for Jenkins (some others are also supported)
  • To recompile and test after every file change and save, use npm run watch. This watches the source directories and launches processing and testing as needed.
  • To clean, build and run all client side tests once, use npm run test-client

Server side

Junit4. Tests are located in src/test/<programming language>, e.g. src/test/java or src/test/ruby.

Tests depend on rgwch~vertx-mod-mock~x.y.z and will run against database mocks.

Download junit-4.x.jar and hamcrest-core-1.x.jar and copy them to a suitable directory. Let $JUNIT_HOME point to that directory. Make sure, $VERTX_HOME is set correctly and that testtools-2.0.3-final.jar (the vert.x test support) is present in the $VERTX_HOME/lib directory. If everything is okay, you should be able to run the full test suite with npm run test-allfrom the webelexis-base directory. The runner will download all dependencies automatically, so first run can take some time.