Testing JavaScript with JUnit

As a test-infected developer, I don’t know how I missed this cool project called JsTester. Matthias pointed me to the project’s homepage and after taking a quick look I’m really impressed. The usage seems easy, after loading the js file, testing can be done using the well known assertions like assertTrue, assertNull and etc. It uses rhino engine by the way.

All of these are the good sides, but I’ve also observed two main weak points, one is the lacking of documentations and other is the testing way. When writing the junit test, one must include an object of type JsTester to the test, also call jsTester’s setup and tear down methods explicitly. It could be much easier if there is a TestCase like AbstractJSTestCase which does this init stuff and more. Also give access to the jsTester for the test which implement it. Anyway the project is very new and I hope Andres Almiray will have time to improve it.

2 Responses to Testing JavaScript with JUnit

  1. I’m glad you found the project useful. The reason JsTester does not extend TestCase is to favor composition in other testCases, but if you only need to test js code then it makes sense to have a JsTestCase. I’m always open to suggestions/criticism/ideas on the project, please feel free to post any feature request on the project page.

    BTW, I’ll see to the docs in the meantime.

  2. stritti says:

    I use this also at log4js. The only limitation is, that the DOM of the browser can not be simulated currently.

%d bloggers like this: