From the online definition:
Karma: is a tool which spawns a web server that executes source code against test code for each of the browsers connected. The results of each test against each browser are examined and displayed via the command line to the developer.
Jasmine: is a development framework for testing js code. It does not depend on any other JavaScript frameworks. It does not require a DOM. And it has a clean, obvious syntax so that you can easily write tests.
My question is, does Karma require Jasmine to run, does Karma depend on Jasmine since Jasmine is a framework and Karma is a tool which runs on that framework and runs the written tests?
I'm using both of them with my angular2 project.
Karma is client-side test runner and doesn't depend on Jasmine. It can run without any testing framework at all.
It has plugins for major testing frameworks, including Jasmine and Mocha.
Yes, Jasmine and Karma can co-exist.
Jasmine is a javascript based framework that we use to write unit
test cases. Alternative to jasmine is Mocha.
Karma is a test runner, which runs unit test cases on browser. And It can be used with all type of unit test frameworks. And It's easy to integrate with all CI tools like Bamboo and Jenkins.
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.
We run a CI environment with Jenkins and the Project using ExtJS 5.1.1.
I try using Chutzpah test runner, using mocha framework JavaScript unit test.
With JavaScript test without ExtJS 5.1.1 testing run successfully.
But JavaScript with reference ext-all.js, there are no success. We have time out error in Blanket.js (error blanket_mocha.js line 5141) testing are not succeed and coverage.xml won't generate.
I'm looking for other way how run JavaScript test (ExtJS) in Jenkins with mocha framework and have code coverage report generate.
We already have Grunt run in Jenkins to do JavaScript combine and minify.
Is this possible to using Grunt to run mocha test and generate coverage.xml in Jenkins?
Please help me out if there is some other way to achieve the same thing. Any suggestion are highly appreciated.
I know that Karma is a test runner for JS Unit Testing frameworks like Jasmine or Mocha. And PhantomJS provides headless browser for running Jasmine or Mocha Tests.
But, what is the difference between Karma and PhantomJS? Are they two competing tools, or do I use PhantomJS on top of Karma to run my unit tests without a browser?
PhantomJS has nothing to do with testing. In the unit testing scope it would become one of the target browsers.
PhantomJS allows you to run unit tests in a browser when a desktop environment doesn't exist.
Karma is a runner that provides the finished reports on how successful the tests where.
Jasmine is the library used to write unit tests.
So to clarify
Jasmine unit tests are run by Karma inside the browser PhantomJS.
It seems like you have somewhat already answered your own question, but I'll expand what you have mentioned.
Karma is a test running framework that is largely test framework language agnostic. It has a rich plugin ecosystem that allows you to heavily customize how, when, and why your tests run.
In order to test Javascript, we often need to test against an incarnation of the DOM. There are numerous plugins that allow you to wire into different browsers such as karma-chrome. These plugins bootstrap the required browser and execute your tests against the browser.
However, there are times when you want to run without a physical browser being installed on the target test box. this is where PhantomJS comes in. It is a headless browser that can be run without being installed on a target machine. It cannot replace Karma. If you want to describe it as a "competitor", it would be a competitor to IE, Firefox, Chrome, and Safari.
I wrote the Jasmine test for the javascript. I am trying to run the Jasmine tests using Phantomjs. I downloaded the Phantomjs from Phantomjs.org and tried running it using phantomjs.exe //path to phantom jasmine http://localhost/myJasmineTestRunner.html. Googling doesn't help me out. Can someone suggest me how to test jasmine tests using phantomjs.
Running the Tests
In order to run our jasmine test suite on the command line, all we need is:
PhantomJS
Installing PhantomJS from phantomjs.org is fairly trivial (at least on a mac).
A URL to our Jasmine test suite
We already covered jasmine test suites, so we have a URL to a jasmine test suite.
A script that loads our URL and parses the results
Fortunately, PhantomJS provides a working jasmine runner example – all we have to do is download it and use it.
Once we got these, all we have to do is run the following command:
phantomjs
It doesn’t take more than a few seconds(!) and we are provided with the test results.
This is it.
Now, lets run it with our build tool.
* For the purpose of this article, lets assume PhantomJS is installed on the system, our jasmine runner is located at /path/to/run-jasmine.js and our jasmine test suite is located at http://localhost/js/test/unit/
Source.
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.