I work with developing web stuff that contains javascript that to some extent holds more logic than just animations and moving values around. I would like to implement some unit tests for that kind of logic.
I want to find some way to write these tests in javascript, and have them run whenever I build the web project in maven. Since the code I want to test deals with logical stuff contained in methods or objects, I don't feel I should have to have a server running. Also, I've read about stuff like Rhino, which makes me feel like there should be no need to have a browser starting somewhere just to execute the javascript.
I'm not particularly concerned about browser differences - I rarely find I run into problems in that field, and when I do it's always about styling or rare DOM issues. I want to test that I can add one and one and end up with two.
I've googled around some, and I find many frameworks for unit testing of javascript. Also after filtering out my picky demands I can still find a few products. Those things tend to lead me to dead web pages though. I found http://code.google.com/p/javascript-test-maven-plugin/ which seems nice, but it's still in a beta version, and I'm struggling to have my maven locate the repository.
Does anyone out there have some recommendations or hints?
One reason for looking at unit tests for javascript is that the language seems perfect for it. Having worked with mocking frameworks in Java, I often find I end up with pseudo-closure stuff and notations that would just disappear if I did the same thing in javascript - you hardly need a testing framework at all besides imposing structure and integrating with maven's test phase and Jenkins.
The Maven surefire plugin is easy to use. It has only one goal: test. Therefore, with the default configuration, we can execute all tests in the project by the command mvn test.
JavaScript Unit Testing is a method where JavaScript test code is written for a web page or web application module. It is then combined with HTML as an inline event handler and executed in the browser to test if all functionalities are working as desired. These unit tests are then organized in the test suite.
Those tests can be run directly in your IDE, by right-clicking on each test class, or by running ./mvnw clean verify (or ./gradlew test integrationTest if you use Gradle).
I was looking for the same thing.
I've never used it (just started to look into javascript unit testing) but Jasmine seems to be very popular.
https://github.com/jasmine/jasmine
So naturally there is a maven plugin for it.
https://github.com/searls/jasmine-maven-plugin
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With