Presented at Bucharest Java User Group, http://www.bjug.ro/editii/5.html . Project source code available at: https://github.com/bucharest-jug/dropwizard-todo
4. Why?
REST services are nice but we need an UI that
is:
● easy to develop against the API
● easy to test (cross-browser)
● brakes when API evolves - but informs us
what changed
● can have continuous integration with our
service
5. Tools
● Backbone - MVC for the Browser
● Require.js - modules for JS - put some order
in that chaos !!
● Jasmine - JS BDD and unit testing
● HtmlUnit - "GUI-Less browser for Java
programs"
● jasmine-maven-plugin - combines Jasmine,
HtmlUnit and Requirejs into a Maven plugin
6. Backbone.js
● gives structure to web applications
● provides: models, collections and views
● binds view to collections/models by custom
events
● declarative event handling
● views can be rendered detached from DOM!!
9. Backbone conclusions
Allows us stay away from DOM
manipulations so we can test things in
isolation
10. Require.js
Is a file and module loader for JavaScript and:
● puts structure in to the web application
● fights against namespace pollution => less
weird bugs !!
● has some nice optimization features
14. Jasmine features
● does not depend on DOM
● has very nice semantics
● can use Spyes to inspect/mock calls
● comes with jQuery support
● you can even test for events like: click, blur,
etc.
15. Sample Jasmine Spec
describe("mode/todo Todo Collection", function () {
var collection
beforeEach(function () {
// initialize collection before each test case
})
it("loads data from the proper url", function () {
expect(collection.length).toBe(1)
})
})
17. HtmlUnit provides:
● support for HTTP/HTTPS
● cookies
● forms, clicking links,
● most important HTTP: POST, GET, etc.
● JavaScript
Use it when you need to test code that runs in
the browser!
19. Jasmine Maven Plugin - esentials
● built on HtmlUnit with Jasmine, + Require.js
● it helps you practice TDD/BDD as you write
JavaScript
● it can run as part of your build with no added
configuration on your part
● also supports CoffeScript
21. Jasmine Maven Plugin - benefits
● you can integrate with CI infrastructure
(Jenkins)
● has multiple browser support => test your
code against I.E. 6,7,9, Firefox, Chrome, etc.
● we can test JS models with the fixtures used
in Java !!