Reputation: 10303
This is a noob question.
I am going to write a string manipulation function, which has nothing to do with web browsers. Now I would like to test that function.
I know how to do that in Java with JUnit
: I write a few test cases and make JUnit
run the tests cases manually or automatically (during the build).
In case of Java Script
I can write a few test functions, prepare an HTML page, which invokes these functions, and load this page in a browser.
Is it really the only option to do unit testing for Java Script
?
Upvotes: 2
Views: 549
Reputation: 8439
No, page output is not the only option. There's another option to output your results to the console (F12 in most browsers will open that up for you). One of the frameworks that outputs to the console in its current version is bob.js.
Upvotes: 0
Reputation: 5137
If you are open to testing in a web browser. I recently wrote a JS unit test class that may help you out. You can run various tests separately or you can execute multiple tests defined in an array with one function. You can see examples of the usage on GitHub.
https://github.com/jakesankey/JSTest
Upvotes: 1
Reputation: 1148
You can try usi jasmine http://pivotal.github.com/jasmine/ it's a testing framework for JavaScript that can test outside a browser. You'll still need a javascript execution stack on your testing environment though.
Upvotes: 2