I am actually configuring Jenkins to make a continuous integration of a JS project with unit tests. My problem is that after many researchs I didn't found any tutorial or information about how to proceed to write unit tests in Jenkins.
Should I use other tools (grunt, ant...) with Jenkins or could it do the job alone ? Is there any important plugin to install to make it work ?
Thanks for your answers
What you're looking for is a testing framework with a JUnit Reporter. Jenkins can read your test results from the JUnit report and give you metrics from them.
Jenkins is just for handling the automation of building your code and running your tests in whatever language you need. In order to use it for that, you need to use something like Karma, Mocha, HapiJS's Lab, Unit.js, Jasmine, etc. to actually write and test with.
Related
I'm a big fan of the continuous testing setup offered by NCrunch in Visual Studio, and would love to have a similar setup with nodejs.
When writing JavaScript in node I use Sublime Text 2 as my editor, with tests written using Mocha.
I wondered if there was software (or a ST2 plugin) for achieving similar concurrent testing to that offered by NCrunch when writing .NET code?
After doing some digging around I've decided that the solution for the moment is:
Server-side: Mocha
mocha -w test
Using mocha's built-in watch functionality.
Client-side: Testacular
I'm now using testacular, which is truly awesome. It would be great it if had hooks for running the server-side watch progress in tandem, but not really a problem.
I haven't tried it myself yet but it looks promising: wallaby.js The description from the website has the following description
Wallaby.js is an intelligent test runner for JavaScript that
continuously runs your tests. It reports code coverage and other
results directly to your code editor immediately as you change your
code. Wallaby.js uses various tricks to run your tests as fast as
possible, such as dependency analysis to only execute tests affected
by your code changes and parallel test execution.
We are using Team Foundation Server 2010 and we have some JavaScript unit tests running on our local machines using Jasmine.
We are using the workflow based builds.
Has anyone had any success running Jasmine tests during their builds? Can you break the build if the Jasmine tests fail?
The way I've seen this done is using the Chutzpah Test Runner available on CodePlex: http://chutzpah.codeplex.com/
This allows you to run Jasmine/QUnit tests from a command-line which can then be easily integrated with a TFSBuild using the InvokeProcess Activity.
you should checkout http://www.codit.eu/blog/2015/03/18/continuous-integration-with-javascript-nunit-on-tfsbuild-(part-23)/
The blogpost describes a complete scenario how to execute your JavaScript Unit tests on the Team Foundation Build server. Basically it uses Grunt (taskrunner) and Powershell. It also has an example of code coverage reports that you can use.
I am currently working on some test cases for my website. I've managed to test the back-end functionality using the simple-test framework.
I have some important javascript tools that requires some automatic testing. I know javascript is a client side language and it requires a browser, i am just wondering if its something i can do.
Notice the test must run from Linux CLI.
Thank you
You can install node.js with jasmine-node package to run your tests using cli:
Here's a brief intro to Jasmine:
http://net.tutsplus.com/tutorials/javascript-ajax/testing-your-javascript-with-jasmine/
And here's a tutorial on jasmine-node:
http://www.2ality.com/2011/10/jasmine.html
PS
In order to reference the code to be tested is useful to grasp how module.export works on Node.js ... here you'll find all the info you need to get started: http://jherdman.github.com/2010-04-05/understanding-nodejs-require.html (broken link) http://coppieters.blogspot.be/2013/03/tutorial-explaining-module-export.html
Jasmine is what I use for my Javascript testing. It can be found here :
https://github.com/jasmine/jasmine (UPDATED -- 2015)
I also use JSCoverage to test my code coverage. It can be found here : http://siliconforks.com/jscoverage/
There are several unit testing frameworks out there written for javascript.
You could try something like:
http://testcase.rubyforge.org/
I am just trying to get my head round unit testing in Javascript and RequireJS. I am building a web-app and obviously only want to have tests run in development not production builds.
Questions:
Do you just test when you want to, or do you have JS tests running
on every page load when in development?
If tests are only on demand
then how do you trigger your tests to run? Query strings (eg.
?testing=true) or something like that?
I just need an idea of how people go about testing in development. I am using BackboneJS, RequireJS and jQuery on the front end with a NodeJS/ExpressJS server on the backend.
For a Backbone project at work we have a maven build process that runs our automated javascript tests through jsTestDriver, and we read the results with Sonar. I usually run the tests manually (with 'mvn test'), but I could easily tell maven every time I save a file, for example. I wrote a post that shows how to integrate QUnit, Requirejs, and code coverage with JSTD that is independent of Maven: js-test-driver+qunit+coverage+requirejs. It also contains links to a QUnitAdapter that is way more up-to-date and developed than the one on the jsTestDriver site. I'll update this post when I manage to write about how I got jsTestDriver working with Maven and Sonar. Hope it helps.
Grunt is a popular JS build tool. There's something called grunt-watch that can monitor certain files for change, and execute tasks accordingly. You could easily run unit tests with something like this on every save.
Usually end-to-end tests take longer, and we use the CI for that. I've seen a presentation on Meteor TDD that does end-to-end tests after every save though.
There are many end-to-end test frameworks, and they can run in a headless browser like phantom js using a build tool like grunt. Some frameworks open an actual browser to run the tests, but run via command line and report results using XML.
If you break out your components enough, the tests could have a small enough scope to run on each save.
For some core code I use JsUnit + Rhino on build server. For more complex bits (usually interface) I use selenium (it also runs on build server). I don't test anything on page load, I only use not-compressed versions of scripts.
I don't any solution for integration tests.
We have a rich web client. Our controllers and service facades are written in coffeescript (JavaScript) and jquery. In the past they would have been java.
To run our JavaScript jasmine tests from Jenkins/Hudson, we use java's junit and htmlunit to load a test oriented jsp page which includes the jasmine specs.
When the Htmlunit tries to run, it blows up trying to getPage() probably because of an XML parser class path which is extremely challenging to track down in our world.
We just want to be able to run our JavaScript tests from Jenkins and have it report failure if a JavaScript test does not pass. We are just using jsp and htmlunit in order to run JavaScript tests. Can we load the JavaScript tests and javascript code into a JavaScript engine with Jenkins as the thing that kicks it off? If so, how?
Sounds like you're in a Java environment. My jasmine-maven-plugin might be a good fit.
Jasmine Reporters would also be a solution. It has instructions for running headlessly via PhantomJS for example, and it can generate JUnit XML so Jenkins can understand the test results natively, graphing test count, duration, and failure over time.
Also, the "xvfb-run" wrapper often provided with xvfb is a great help here, so you can do "xvfb-run phantomjs.runner.sh ..." in a truly headless environment.
I've previously solved this problem by running the tests with a node.js plugin called jasmine-node
This solution of course requires node.js and a few node modules to properly run the jasmine tests. There is no real browser running the tests, but an emulated one using a module called jsdom, which basically creates a headless browser, and more specifically, a DOM, which the tests can interact with.
There's node modules for jQuery, underscore and propably other too, so these can be tested too. You can even skip the whole browser emulation if you'd rather run the tests in a browser, though I find it too cumbersome compared to automated Jenkins testing.
jasmine-node generates jUnit test reports, which Jenkins can interpret just fine.
I just realized there is some jenkins-jasmine-node plugin that might ease this process.
Grunt is your friend
use grunt http://gruntjs.com/
with grunt jasimine https://github.com/gruntjs/grunt-contrib-jasmine
with nodejs http://nodejs.org/
on jenkins using https://wiki.jenkins-ci.org/display/JENKINS/NodeJS+Plugin
got this setup and it's really nice, plus this gives you a place to start making your build server do other nice things such as deployment, unit testing, etc you know, other nice things
Can you use selenium? That would actually use a real browser then and get as close to the real environment as possible.