what are options for automated unit testing in angular js - angularjs

I'm new for unit testing so i want to know best automated option for angular js app testing.
I found some framework call Jasmine and Karma but I want to know best option.

Related

d3 Automation Testing

I need to test some d3 based Angular components and had thought to use Selenium IDE or Kantu, but it seems that these tools cannot record interactions with SVG elements. Are there any tools that would allow me test in this way? Or will I need to rethink the problem and use a different type of testing?
There is a tool specifically made for UI testing of angular.js pages. It's called protractor . In this, test scripts have to be written in Javascript. Protractor is for end-to-end testing.
If you are going to do unit testing , then the gold standard for unit testing angular code is Karma. Karma was created and is maintained by the core Angular team and provides many utilities that make it easy to test angular apps.
A combination of both protractor and karma can completely cover an angular app functionality.

How to organize AngularJS unit tests from multiple projects?

We have a VS2015 web solution with multiple projects where we use AngularJS. We decided to start writing unit tests for AngularJS code and picked up Jasmine framework. It means .js files with modules are not in one project only and I'm wondering how to centralize the testing.
What to do with .js files from different projects in order to be available for centralized unit testing?

how to test angularjs app using Protractor

I am currently using Karma and Jasmine for doing the unit test my first angular App.
Now I want to test my App's HTML elements but I couldn't find any way to do that in karma test runner. I read that this is only possible with protractor. I have no idea of writing and running test in protractor, can anyone help me out?
OR
Suggest if there is a way to test HTML in karma?
Because I am using Karma for controller testing, is it possible to test HTML as well in Karma then it'll be super helpful.
For protractor, can I test my controller as well in protractor??
First of all, there are two very different major types of tests/categories that are usually written for AngularJS applications: unit tests and end-to-end tests.
For unit testing of your directives, controllers, services - use karma.
For end-to-end testing - use protractor.
Related quote from the Protractor's FAQ:
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.
See also:
Should I be using Protractor or Karma for my end-to-end testing?
Can Protractor and Karma be used together?
Advanced Testing and Debugging in AngularJS

AngularJS testing? Unit Testing and E2E testing?

I have been reading that karma is used for angular unit testing and protractor is for end-to-end testing. If we want to have both unit and E2E testing in my angular application, then how do should it look like? How do I incorporate both? In order to have both of these tests included in our suite, should we use both karma (for unit testing) and protractor (for E2E testing) for the same application? Is that a healthy way to go about it?
P.S: Post is open to all the approaches to achieve this.
It's possible to run unit tests on Protractor but it's better to separate unit and e2e test runners.
https://github.com/angular/protractor/blob/master/docs/faq.md#why-both-karma-and-protractor-when-do-i-use-which

Is there a code coverage for HTML using Karma when doing angular e2e test?

We can use coverage to see how much javascript code is covered with our unit testing. With e2e testing we are literally testing view components in HTML code against controller. So the question is, is there same code coverage available for how much of HTML DOM elements are covered or touched in our e2e testing? I agree, there is a big difference in the execution path testing and UI testing. but curious.
Thanks
As I know e2e testing use your files served by your web server, for unit test they are served directly by karma, e2e testing is mostly used to be sure your page work like you expect, end-to-end test use your server side and client side. That's why you typically never expected to have 100% e2e coverage because they are more fragile.
So people focus on unit test (testing all edge-cases), and they add e2e test to be sure the behavior of the page works correctly.
You can use istanbul and build the coverage report with karma.
http://gotwarlost.github.io/istanbul/
Or this article : http://lkrnac.net/blog/2014/04/measuring-code-coverage-by-protractor/ sum up how to use protractor e2e to generate coverage report of your e2e tests. Using using this tool : https://github.com/r3b/grunt-protractor-coverage
Hope it's help.

Resources