Quite simple, it's a custsom Java Junit Runner that allows you to embed Javascript Unit tests (using Jasmine) in your Java-based projects. It fully integrates with your most beloved IDE, your most hated version control system and of course your most needed CI env.
So let's rephrase:
* Run Javascript (the <ahref="https://github.com/pivotal/jasmine"target="_blank">Jasmine</a> - behavior driven - way) "specs" in Java
* Talks like a duck-erhm, any other Junit Java test. Just use a custom annotation (see below)
Yes! It allows you to test your jQuery plugins or your spaghetti GUI+Logic code, neatly woven together.
You can use <ahref="https://github.com/velesin/jasmine-jquery"target="_blank">jasmine-jquery</a> matchers. I've modified `jasmine.Fixtures` to support Envjs+Rhino. This means you can test stuff like this:
```javascript
beforeEach(function() {
loadFixtures("myFixture.html");
});
it("should be visible and blue", function() {
var div = $('#myDivInFixtureHtml');
expect(div).toBeVisible();
expect(div.css('color')).toBe('blue');
});
```
Fixtures are automatically cleaned up. See src/test/javascript/lib/jasminedir/jasmine-jquery-rhino.js
#### But wait, CSS Style Parsing does not work in Envjs 1.2, how come this does?
See env.utils.js. Cover your eyes - hacks present.
2. Create some Jasmine specs, place them in some folder.
3. Create a Junit test class, annotate it with _@RunWith(JasmineTestRunner.class)_
4. Fill in the blanks using @JasmineSuite
## More options
_@JasmineSuite_ allows you to set these options:
* debug: use the built-in Rhino debugger (gives you the chance to set a breakpoint before firing the test suite)
* jsRootDir: the javascript install root dir. Jasmine and other should be installed here (see source)
* sourcesRootDir: your production JS files root dir.
* specs: one or more spec file to run. Default behavior: use java Class name (replaces Test with Spec, see example)
* sources: one or more JS production file which your spec needs (included before specs, d'uh)
* generateSpecRunner: (the HTML output, useful for firefox/firebug debugging etc)
## Requirements
Currently, Jasmine Junit Runner relies on Rhino 1.7R2 (+ es5-shim) & Envjs 1.2 to interpret JS code. It also uses Jamsine 1.0.2 to read your spec files. All js libs are located in test/javascript/lib .
### Dependencies Overview
See the _pom.xml_ (Maven2) - you can build the whole thing using:
> mvn clean install
* Rhino 1.7R2 + es5-shim 0.0.4 (not needed if you'll be using 1.7R3)
* Envjs 1.2 + required hacks in env.utils.js
* Jasmine 1.0.2
* Java libs: commons-io and commons-lang (test libs: mockito and fest assert)
* * *
# Examples
## Running a spec file as a Junit test
### Use the default spec naming convention
If you do not specify _specs_ with the annotation, the runner will auto-pick the spec name using your test class.
The below test will load _myAwesomeSpec.js_ from the specs dir (jsRootDir + '/specs/').
* You can define n number of _PUBLIC_ methods annotated with @Before or @After
* You can, but don't have to, take the _RhinoContext_ object as the only parameter. This allows you to set stuff up in JS space before running the spec.
### Generating a spec runner
Your awesome test (example 1) would for instance generate this html file:
```html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
You can inspect the output using firefox, or debug in your spec file using firebug.
### Debugging in Java
When the debug mode flag has been set to _true_, you can use the <ahref="http://www.mozilla.org/rhino/debugger.html"target="_blank">Rhino Debugger</a> to set breakpoints.
After pressing "GO", the tests will run and you can inspect stuff and step through the code.
Integrated debugging into for example Eclipse does not work for the moment.