Karma is a browser test runner.

The idea is that browsers do not have natively a concept of loading tests files, running them, and reporting results. What karma does is (roughly) :

  • starting a small web server to serve "client-side" javascript files to be tested (1)
  • also serve the "client-side" javascript files with the tests (or Specs, as they're often called) (2)
  • serve a custom web page that will run javascript code for the tests (3)
  • start a browser to load this page (4)
  • report the results of the test to the server (5)
  • karma can then again report the results to text files, the console, anything your CI server likes, etc...

Looking at each part :

(1) Those files will be your actual js files ; you will tell karma how to load them. If you use requirejs, there is a karma plugin, and some config is needed.

(2) Those tests can be written in a variety of Javascript testing framework (Jasmine, QUnit, Mocha) ; this is JS code that is run in the browser.

(3) The custom web page will be a bit different for each testing framework ; this is why karma has plugins for different frameworks.

(4) Karma can launch the page in many browsers (FF, Chrome, or headless browsers like PhantomJs.)

(5) Reporting to karma is, again, framework-dependant, and dealt with karma plugins.

So to answer your questions :

  • in Java, most people use JUnit which is both a framework to write tests and run them, but does not have the problem of differentiating the environment in which tests are run and the one in which test reports are aggregated ; karma would be the missing piece between a JUnit Suite and a JUnit TestRunner
  • Yes, you can do everything that karma does "by hand" - pick one framework (jasmine, qunit, mocha) and follow instructions. The advantage of karma is that it provide a solution out-of-the-box, if you're in a standard setup.
  • Karma can be used for both unit test (with jasmine / qunit / whatever) and integration tests (which will use another API, like webdriver, to drive the browser)
Answer from phtrivier on Stack Overflow
Top answer
1 of 3
440

Karma is a browser test runner.

The idea is that browsers do not have natively a concept of loading tests files, running them, and reporting results. What karma does is (roughly) :

  • starting a small web server to serve "client-side" javascript files to be tested (1)
  • also serve the "client-side" javascript files with the tests (or Specs, as they're often called) (2)
  • serve a custom web page that will run javascript code for the tests (3)
  • start a browser to load this page (4)
  • report the results of the test to the server (5)
  • karma can then again report the results to text files, the console, anything your CI server likes, etc...

Looking at each part :

(1) Those files will be your actual js files ; you will tell karma how to load them. If you use requirejs, there is a karma plugin, and some config is needed.

(2) Those tests can be written in a variety of Javascript testing framework (Jasmine, QUnit, Mocha) ; this is JS code that is run in the browser.

(3) The custom web page will be a bit different for each testing framework ; this is why karma has plugins for different frameworks.

(4) Karma can launch the page in many browsers (FF, Chrome, or headless browsers like PhantomJs.)

(5) Reporting to karma is, again, framework-dependant, and dealt with karma plugins.

So to answer your questions :

  • in Java, most people use JUnit which is both a framework to write tests and run them, but does not have the problem of differentiating the environment in which tests are run and the one in which test reports are aggregated ; karma would be the missing piece between a JUnit Suite and a JUnit TestRunner
  • Yes, you can do everything that karma does "by hand" - pick one framework (jasmine, qunit, mocha) and follow instructions. The advantage of karma is that it provide a solution out-of-the-box, if you're in a standard setup.
  • Karma can be used for both unit test (with jasmine / qunit / whatever) and integration tests (which will use another API, like webdriver, to drive the browser)
2 of 3
77

One shorter way to understand the difference:

People testing with plain Jasmine / Mocha most likely are running all the code with the Node virtual machine.

Adding Karma to the mix (on top of your existing framework of choice) will run your test suite with the engine of other browsers.

By doing this you get the little extras you get with a browser environment. It will be easier to test DOM related code, but you will also be giving up to the extra resources given by the Node engine (like filesystem / shell access)

๐ŸŒ
StackShare
stackshare.io โ€บ stackups โ€บ jasmine-vs-karma-runner
Jasmine vs Karma | What are the differences? | StackShare
Jasmine emphasizes simplicity and readability with its behavior-driven development approach, while Karma serves as a test runner, offering a testing environment and supporting features like coverage and CI integration.
Discussions

Jest vs Karma/Jasmine which testing library you will prefer to use and why?
We moved to jest because of speed issues and of course blog posts outlining how and why it's better. Having said that... I hate both. Both are slow. Both have their own specific issues. But I've invested so much time in making it work that I'm sticking with jest until something better appears. More on reddit.com
๐ŸŒ r/Angular2
13
3
October 24, 2022
What is difference between Jasmine and karma? - Ask a Question - TestMu AI Community
What is the main difference between Jasmine and Karma? More on community.testmuai.com
๐ŸŒ community.testmuai.com
0
July 15, 2022
jquery - standalone Jasmine vs Karma - Jasmine - Stack Overflow
I'm new to testing in general, and have been teaching myself Jasmine. I'm trying to understand the differences between running Jasmine and jQuery-Jasmine in Karma vs running Jasmine by itself. The More on stackoverflow.com
๐ŸŒ stackoverflow.com
Angular testing techniques Jasmine vs karma vs protractor in Angular 2? - Stack Overflow
Can anyone tell me about the difference between these above 3 techniques? ... Save this answer. Show activity on this post. Jasmine is a behavior-driven development framework for testing JavaScript 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. Karma ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
๐ŸŒ
Medium
medium.com โ€บ knowledge-pills โ€บ how-karma-and-jasmine-differ-as-testing-frameworks-in-javascript-494f7c4f53f
How Karma and Jasmine Differ as Testing Frameworks in JavaScript | by Fuji Nguyen | Knowledge Pills | Medium
March 23, 2023 - Features: Karma includes features like test coverage reporting, continuous integration, and test result watching, while Jasmine focuses on providing a simple, intuitive testing syntax.
๐ŸŒ
Reddit
reddit.com โ€บ r/angular2 โ€บ jest vs karma/jasmine which testing library you will prefer to use and why?
r/Angular2 on Reddit: Jest vs Karma/Jasmine which testing library you will prefer to use and why?
October 24, 2022 - ... Jest not using a full real browser has caused me issues recently. So I am starting to lean more towards Karam currently. ... They do component testing now. ... Jasmine is a superset of Jest and Jest has quicker tools using a mock browser.
๐ŸŒ
CodeCraft
codecraft.tv โ€บ courses โ€บ angular โ€บ unit-testing โ€บ jasmine-and-karma
Jasmine & Karma โ€ข Angular - CodeCraft
Karma handles the process of creating HTML files, opening browsers and running tests and returning the results of those tests to the command line. If you use the Angular CLI to manage projects it automatically creates stub Jasmine spec files ...
๐ŸŒ
StackShare
stackshare.io โ€บ stackups โ€บ jasmine-vs-karma-runner-vs-mocha
Jasmine vs Karma vs Mocha | What are the differences?
Jasmine - DOM-less simple JavaScript testing framework. Karma - Spectacular Test Runner for JavaScript. Mocha - Simple, flexible, fun javascript test framework for node.js & the browser
๐ŸŒ
Slant
slant.co โ€บ versus โ€บ 5103 โ€บ 5105 โ€บ ~jasmine_vs_karma
Slant - Jasmine vs Karma detailed comparison as of 2026
You don't need to download a fancy tool to see how your app looks in a number of different browsers, now that Karma would do the job for you. Thanks to Karma, you won't need to spawn up a new terminal just so that you can test your app, you can now code and test right from the IDE ยท Pivotal aren't responsive to pull requests, though they have made repo changes within < 3 months ยท Currently Karma doesn't support testing of apps built on NodeJS. So if you have a node app, you don't want to use Karma, Mocha or Jasmine can do the job for you.
Find elsewhere
๐ŸŒ
Quora
quora.com โ€บ For-angular-2-what-are-the-differences-between-karma-protractor-and-jasmine
For angular 2+, what are the differences between karma, protractor, and jasmine? - Quora
Answer: Karma is a test runner for running your unit tests. It doesn't provide APIs to stub mock or assert. Rather it just allows you to run your spec files on various browsers and allows various reporters to capture test results.
Top answer
1 of 2
14

Karma and Jasmine's SpecRunner.html are both test runners (aka spec runners). The difference between the two is that Karma is an application that runs outside the browser, while SpecRunner is a normal HTML file with a bunch of script references that you open up in a browser.

A test runner that lives outside the browser gives you a number of benefits:

  • automatically run tests in one or multiple browsers at once
  • automatically run tests on file changes, without having to manually refresh the browser
  • file pre-processing, i.e.
    • compiling TypeScript to JavaScript before running tests
    • inlining HTML templates into JavaScript
  • file/report generation, i.e. test coverage reports
  • test framework flexibility
  • easily include/exclude test and source files using file and folder patterns rather than trying to wrangle 100s of <script> references in a HTML file
2 of 2
2

I haven't used jasmine-jquery, but for jasmine tests with Karma, Karma uses the karma.conf.js to discover external dependencies (such as jasmine-jquery). Particularly the files property. Some nice examples are here If you're running jasmine tests with jasmine's SpecRunner.html, you need to make sure anything you use is linked in the SpecRunner.html with script tags.

As for testing click handlers, one good bet might be just to call the click handler functions directly. It sounds like if you want something more realistic, you're getting closer to functional testing. For that you might consider incorporating nightmare to automate user interactions such as clicks, etc.

๐ŸŒ
Educative
educative.io โ€บ answers โ€บ mocha-vs-karma-vs-jasmine-what-to-use-when
Mocha vs Karma vs Jasmine. What to use when?
Jasmine includes both an assertion library and a testing framework. An assertion library is a syntax written by the developers themselves to test out a code. On the other hand, Mocha does not include an assertion library giving the developer ...
๐ŸŒ
Dot Net Office
dotnetoffice.com โ€บ 2022 โ€บ 03 โ€บ introduction-of-jasmine-karma.html
Introduction of Jasmine & Karma - Dot Net Office
Jasmine has the test double functions called spies , A spy can stub any function and track all calls to it and its arguments ... Karma is a testing automation tool created by the Angular JS team.
๐ŸŒ
Madanswer
madanswer.com โ€บ 46675 โ€บ what-is-difference-between-jasmine-and-karma
What is difference between Jasmine and karma? - Madanswer Technologies Interview Questions Data|Agile|DevOPs|Python
It can be tedious to manually run Jasmine tests by refreshing a browser tab in multiple browsers every time we make a code change. Karma is a tool that allows us to spawn browsers and execute Jasmine tests inside them from command-line
๐ŸŒ
Zymr
zymr.com โ€บ home โ€บ blog โ€บ angular unit testing with karma and jasmine
Angular Unit Testing With Karma And Jasmine
July 22, 2024 - It allows users to add new features without interrupting any other part of their application. Jasmine is a JavaScript testing framework and Karma is a node-based testing tool for JavaScript codes across multiple real browsers.
๐ŸŒ
Brainvire
brainvire.com โ€บ home โ€บ unit testing in angular with jasmine and karma
Unit Testing in Angular with Jasmine and Karma [Complete Guide]
September 20, 2024 - Karma is a testing tool for JavaScript codes that is node-based. It can be grouped under Browser Testing. Jasmine, on the other hand, is an open-source framework used to build tests. It allows you to write various kinds of tests with many features.
๐ŸŒ
DZone
dzone.com โ€บ coding โ€บ frameworks โ€บ angular unit testing with karma and jasmine
Angular Unit Testing With Karma and Jasmine
June 1, 2023 - Jasmine is a JavaScript testing framework, and Karma is a node-based testing tool for JavaScript codes across multiple real browsers.
๐ŸŒ
StackShare
stackshare.io โ€บ stackups โ€บ jest-vs-karma-runner
Jest vs Karma | What are the differences? | StackShare
Karma - Karma is not a testing framework, nor an assertion library. Karma just launches a HTTP server, and generates the test runner HTML file you probably already know from your favourite testing framework.
๐ŸŒ
Mattermost
mattermost.com โ€บ home โ€บ choosing a javascript testing framework: jest vs. jasmine vs. mocha
Choosing a JavaScript testing framework: Jest vs. Jasmine vs. Mocha
May 24, 2022 - Although the CLI app does most of the Jasmine and Karma configuration for us, we can still tweak the config by editing karma.conf.js at the root of our project. However, much like Jest, using Jasmine to test a non-Angular app requires lots more setup. For example, to test a React app using Jasmine, we need to install six different ...