124
votes

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.

1
Better fit for software recommendations. Though if you do post this question there you will have to elaborate what your requirements are. Related metauser2033671
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
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
See my answer here for more detailed discussion of use cases, advantages and limitations of Karma and Protractor: stackoverflow.com/a/29619467/1614973Dmitri Zaitsev
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 <script>s to the browser so they run in the same interpreter, mocking possible, but is not designed for end-to-end testing with native events as if a real user were acting.robert4

1 Answers

179
votes

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.