AngularJS Testing: Protractor, Karma, Jasmine in a Yeoman App

e2e-testingjasminekarma-runnerprotractor

I use this yeoman generator:
https://github.com/Swiip/generator-gulp-angular

It installs three testing applications: Jasmine, Karma , Protractor
According to this article (Should I be using Protractor or Karma for my end-to-end testing?), I should use: Karma for small tests of e.g. a single controller. Protactor if I want to test the whole app and simulate an user browsing through my app. According to this blog (http://andyshora.com/unit-testing-best-practices-angularjs.html) I would use Jasmine for unit testing and Karma for end-to-end integration tests.

I guess Jasmine is the language where tests are written and the other two execute the code, is that correct? Also if I never wrote a test which is more important to learn first/ to focus on?

Best Answer

Karma is a test-runner, so it runs your test. Jasmine is the framework that let you write test

In my opinion in Angularjs you :

  • must unit-test services, because your business code is there.
  • should unit-test controller, because users actions are there.
  • may unit-test custom directives (if you plan to share that directive with others, it's a must)

Protractor is made for E2E testing (tests navigation like a real user). It combines WebDriverJS with Jasmine and lets you write End-to-End tests (you simulate a real browser and taking real actions) with Jasmine syntax.

That kind of test is also really important in a web app.

You should not test everything, especially at the start of the project, those kinds of tests usually come with a high level of maintenance (i.e., when you change a screen you may have to change the test).

What I do is test the critical path and features. I made a reading app, so in my case, it was login, sign up, payment, access book, and access reader.

Related Topic