I'm writing an html/js (ember) chat app using socket.io as the backend. (I know: original, much?)
For some of my end to end integration tests (i.e. Client AND Server) I would like to test the interaction between two clients. I know I can get this done with selenium-webdriver and a testing framework such as mocha but I'd really like to use a nice test runner like Karma or the one that comes with QUnit and I'm a bit stumped as to how to get either of those to create and interact with two clients at once.
QUnit in itself is not a test runner. It is a testing framework. Karma on the other hand, is a test runner.
QUnit very much likes to test units of code, just as any xUnit framework does. Running integration tests in unit-testing settings is not advisable. As the comment below from Andy clearly demonstrates, QUnit can be used in different settings, but there not in the sense of an xUnit-type testing framework.
As for testing socket.io applications, this SO answer might be helpful to you?
Swizec Teller has a tutorial on testing socket.io code, and Liam Kaufman has a blog post on testing a chat application written with socket.io.
Related
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.
I'm setting up an Express / AngularJS project. Express will serve the static assets for AngularJS and act as an API server. I want to unit test my express controllers and endpoints.
I may have some scenarios as well that need to be tested (like first create a user, then login, etc). I also want code coverage. Oh, did I mention that it's all in CoffeeScript as well?
I'm using karma and jasmine for my Angular tests. I'd like to stick to similar frameworks for the node.js layer.
Any suggestions on getting started?
supertest is great for this. You should be able to use it with jasmine or mocha easily. supertest-session can help with mocking out a logged-in user.
Have a look at some of these mocha + supertest tests if you need an example: https://github.com/focusaurus/peterlyons.com/tree/master/test/application
I want to test my AngularJS application using Selenium and PhantomJS, but I am not finding an easy to start resource or video tutorial. Can you please suggest some good resource as a starting point.
Have you looked at this tutorial?
The tutorial itself seems decent. You might have to change some stuff depending on what you choose as your test-runner (this tutorial chose Mocha).
I'd also look at Karma and Protractor which are built by the AngularJS team.
Protractor is targeted more towards end-to-end testing in AngularJS apps.
If you're set on Selenium, you could also look at Nightwatchjs which is also end-to-end and runs against a Selenium server but requires Node.js. Nightwatchjs could be compared to Protractor but seems like it has easier-to-understand syntax.
As #Nima-Vaziri said, you should have a look at Karma to run unit tests on your app. This article will help you on this way.
Then to run e2e tests, the new runner developped by the Angular team is Protractor and you can start with this demo : Protractor demo
To understand, these docs were very useful to me:
Protractor Readme
Setting up your browser
Getting started
If you're going to work with AngularJS: you definitely should know about eggehead.io videos! This one is about Protractor. But, there's a lot of video tutorials very interesting to teach you how to build an Angular app!
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 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.