I have been told to make an investigation of the different options for Angular Testing out there, specifically Angular 2. I would like to confirm with you whether my conclusions are right or not.
Can I write unit testing using Vanilla Javascript?
The answer is yes and also you can write Unit Testing using Jasmine.
Unit testing vs TDD
TDD is the approach of writing the test cases before development and then the developer write the necessary code to make this failing test pass.
You cannot do TDD without using unit testing.
With TDD the code is fully tested in advance. Following TDD approach is easy than write unit tests after development.
Which are the mainstream testing frameworks?
Mocha is one of the most used libraries for testing purposes out there. But It only provides you with the basic structure you need to do testing. When you need more flexibility or functionality such as assertions, spies, mocks… you must add third party libraries: ChaiJS, SinonJS, ShouldJS. Which makes it difficult to start. No much documentation for using them for Angular 2, either.
Jasmine is also a very popular framework for testing purposes. With Jasmine, you have all the functionality you are going to need out-of-the-box. And have great compatibility with Angular 2. e2e tests should be written using Protractor (which is wrapper of selenium). As a rule: All test that can be written down as instructions for a human interacting with your application should be e2e.
In Brief:
Jasmine - Focus on BDD. Easy for newcomers. Code easy to read. It is a library that covers almost every part of the testing development. You can write unit testing, use it for TDD/BDD. Created by Angular People.
Mocha - Hard for beginners, easy for TDD/BDD. It does not include any library for assertions, expects. Flexible but difficult. Mocha is considered the best library for Javascript testing even though being hard to learn and put into practise.
Jest - Created by Facebook, not as popular as the other ones. This tries to keep things as simple as possible. No much considered for Angular 2 world.
Cucumber - Focus on BDD
More:
Also, browser environment feature which is not available in either (Mocha, Jasmine). For this you will need to use Protractor (wrapper of Selenium) which is well-documented in Angular 2 testing section or others such as: Nightwatch, Phanton, Casper, etc).
Karma Test Runner is used to run your tests in different browsers and show the results in it. (Good for TDD approach).
Jasmine has a great support from Angular community which is definitely a positive point.
Jasmine also allows you to use different libraries for getting more flexibility in the case of assertions for example.
Selenium is a library that run tests on the browser in order to simulate user behavior.
Protractor (e2e, BDD) wraps selenium and add improved syntax and special hooks for Angular.
There is no much information out there to start using Angular 2 Webpack with MochaJS.
Aucun commentaire:
Enregistrer un commentaire