Image processing in your browser - Unit Test automation
Typically, when we test C++ software, we end up with test framework of your choise and test runner. It can be continuous integration server like Jenkins in your company or public Travic-CI service for open-source project.
Moreover, due to browser sandbox, you are not allowed to access canvas data for local files. In practice it means that code like showed below won’t work if you open a HTML page as a local file:
You will have to setup a local HTTP server to serve these tests pages to get this
works. One simple way to do it by using python:
python -m SimpleHTTPServer 8000 will
do the job. However it’s only a partial solution.
Now let’s imagine that you have a lot of these tests. Would you open each page individually, watch how they run and wait to analyze their results? No doubts, you can do it, but this is not automated testing in any way.
To recap, here are a list of problems that exists in browser JS testing:
- A test framework
- Have to open test pages in a browser
- Hard to automate and collect results
- Need local webserver
Since I’m used to Mocha, i will use it. However it’s not obligatory and you can chose any other test framework you like. But as you will see later, with Mocha it’s really simple. ith mocha you can write your scripts like showed below. This is a real test I wrote as an example for JSFeat:
This extension does exactly what we need: it starts a local webserver, open page in phantomjs and run JS test cases. With help of it, we are able to run all our tests using simple command:
Here’s an example output: