124

Should I be using Protractor or Karma for my end-to-end testing?

Angular-seed is using Protractor/Selenium WebDriver for E2E but the angular-phonecat tutorial uses karma.

I read that I should use Karma for unit tests and Protractor for E2E, which seems fine but I thought I would ask on here to get other dev's opinions.

morten.c
  • 3,188
  • 5
  • 36
  • 43
screenm0nkey
  • 16,975
  • 17
  • 53
  • 75
  • 1
    Better fit for [software recommendations](http://softwarerecs.stackexchange.com/). Though if you do post this question there you will have to elaborate what your requirements are. [Related meta](http://meta.softwarerecs.stackexchange.com/questions/8/is-it-alright-to-ask-for-programming-tools) – Professor Allman Feb 12 '14 at 15:42
  • 5
    Karma and Protractor are both used and recommended by the Angular team, but given the state of documentation (ie: there's tons of it and it's difficult to know what's up to date) it's difficult to know which to use and for which purpose. This is a good question and glpretre's answer was exactly what I was looking for, too. – Matt Jul 07 '14 at 21:21
  • 6
    I don't think the question was too broad (Protractor vs Karma). It's frameworks we are talking about here, not just some software, so the question is in it's right place. – CCC Mar 09 '15 at 07:18
  • See my answer here for more detailed discussion of use cases, advantages and limitations of Karma and Protractor: http://stackoverflow.com/a/29619467/1614973 – Dmitri Zaitsev Apr 14 '15 at 16:28
  • My understanding is that Protractor does not allow to test only a part of your app without the presence of the rest (e.g. mocking): the test code isn't even running in the same JS interpreter as the application. No filesystem monitoring for source code modifications and automatic re-triggering of the affected tests. Karma provides these. It sends test code + app code in – robert4 Nov 14 '17 at 14:36

1 Answers1

179

The AngularJS team recommends using Protractor as it's going to replace angular scenario runner:

Angular Scenario Runner is in maintenance mode - If you're starting a new Angular project, consider using Protractor.

quoted from AngularJs documentation.

The tutorial angular-phonecat was developed a long time ago (in 2011 mainly) and has not yet been updated to use some Angular new features like Protractor.

EDIT

In the Protractor Docs - FAQ:

Why both Karma and Protractor? When do I use which?

Karma is a great tool for unit testing, and Protractor is intended for end to end or integration testing. This means that small tests for the logic of your individual controllers, directives, and services should be run using Karma. Big tests in which you have a running instance of your entire application should be run using Protractor. Protractor is intended to run tests from a user's point of view - if your test could be written down as instructions for a human interacting with your application, it should be an end to end test written with Protractor.

Here's a great blog post with more info.

Community
  • 1
  • 1
glepretre
  • 8,365
  • 5
  • 41
  • 56
  • 11
    From Karma FAQ - http://karma-runner.github.io/0.10/intro/faq.html - Can I use Karma to do end to end testing ? Karma has primarily been designed for low level (unit) testing. If it's an AngularJS app, you can use Karma with karma-ng-scenario plugin, however we recommend Protractor for high level testing. – mrwaim Jul 15 '15 at 00:42
  • If I want unit testing as well as e2e testing then i have to configure karma environment for unit testing and protractor for ui testing or e2e testing ? – Sunil Garg Dec 22 '16 at 12:27
  • 2
    @SunilGarg Yes you have to, maybe our starter app structure could help you : https://github.com/glepretre/angular-requirejs-ready (ignore requireJS specifics if you don't use it) – glepretre Dec 23 '16 at 14:00