Reputation: 6138
I have a web application that uses the d3 library for some complex SVG based visualizations.
I have automated tests for my server side code and JavaScript models (I use an MVC like architecture in my JavaScript). These are run on a Jenkins CI server on every commit. Now I need to work out how to test my views.
How do others tackle this problem and what tools do you use?
Some thoughts I've had ...
Thanks!
Upvotes: 40
Views: 7382
Reputation: 2301
Capturing browser and verifying the graph is a good test. But I feel this to be a responsibility of D3 itself than our code.
I was also having similar question. (My Question). Please checkout the answer I posted there.
Upvotes: 0
Reputation: 2475
The example you give are for testing the graphical output. For this you can use a screenshot diff tool like PhantomCSS, Sikuli or roll-up your own with Resemble.js.
But if your question is more genrally about testing D3.js/SVG-based apps, as the title implies, you should look at the D3 test suite. Most tests don't even need an html fixture because they are basically testing the API. If the most important thing for you is the consistency of the visual result, go with a screenshot diff tool. For navigation and UX flow, you are better with browser automation like Selenium. But for unit testing, where you want to ensure having a consistent API and modular code, most test frameworks with spies, fixture and mocking capabilities will do (i.e, Jasmine, Vows, Mocha).
Upvotes: 22
Reputation: 6138
The solution I'm currently contemplating is ...
Upvotes: 0
Reputation: 109232
It sounds like Selenium should do what you're looking for. It drives the web browser and therefore allows you to check what actually happens in the browser instead of assuming that the SVG will be rendered correctly. It allows you to specify unit tests as a series of clicks/key strokes and it integrates quite nicely with Jenkins.
Upvotes: 0