1

I am new to e2e testing. I'm using protractor for angular 4 testing. I am much confused about jasmine, mocha and protractor. My understanding with jasmine and protractor is that jasmine is a testing framework. It can not be used stand alone without any test runner i.e. protractor(e2e testing) or karma(unit testing). Protractor is a test runner that uses jasmine framework. It interacts with browser, without protractor (or any other test runner), jasmine can't interact with browser in e2e testing.

On the other hand, mocha is also a testing framework that has its own test runner i.e. mocha-CLI. It doesn't need any test runner and can be used stand alone for testing. Can any one help me in getting the right concept?

Thanks in advance

Analyst
  • 751
  • 6
  • 15

1 Answers1

1

There are a few things to understand first. There are different stages of testing like Unit testing, End to End testing, performance testing etc. These tests either run on the browser (that means end user) or they run in your code. These tests require a runner for executing. Some examples of runners are Karma, Protractor, mocha-cli, jest etc. Not all of these runners are compatible with all types of testing.

Protractor runs end to end tests and it can use frameworks like jasmine, mocha and cucumber. But protractor runs these tests on the browser so we require a browser to run these tests. This cannot be achieved with mocha-cli out of the box because it does not have browser support, but it can be achieved if the runner was configured to use a browser instance. Protractor supports the above three BDD testing frameworks.

Karma/jest/mocha-cli runs unit tests on your system code. This runner does not require a browser to run the tests as the tests would run on the internal system code and no http requests would be involved. Karma still requires a browser to view the test results as a UI element.

For performance testing with lighthouse, you can start your browser and use jest to run the tests as a zero configuration test runner. But this would require you to create a browser instance.

Bottomline is that testing frameworks are different than test runners. Mocha developed its own test runner to provide light weight unit testing runner for testing code. A framework is used as a testing support structure where you can place your tests systematically to achieve a goal. Whereas a runner is something that does not care what framework your tests are running (till they are compatible with the runner). The runner will just pick up all the tests it finds and execute them.

  • Thanks, for such detailed answer, Actually one thing which still bothers me is that, Jasmine is a framework, Can we execute an e2e test without any test runner in jasmine? i.e. Consider that there is not test runner like protractor, jest, karma mocha-cli etc – Analyst Dec 23 '19 at 10:25
  • @Analyst Yes you can run the jasmine code using something like jasmine-node to run the tests. But it is not suggested for use. Jasmine-node is also a test runner for jasmine. But since there are frameworks out there to help manage a lot of things like logging, reporting, framework to use etc. Using a lightweight runner is not a very good idea. To be precise, jasmine cannot run without a test runner involved. – Sankalan Parajuli Dec 23 '19 at 10:38
  • Maybe this image will help you understand better!! https://image.slidesharecdn.com/protractorforangularjs-150120025822-conversion-gate01/95/protractor-for-angularjs-4-638.jpg?cb=1421724593 – Sankalan Parajuli Dec 23 '19 at 10:40