OpenSource For You - - DEVELOPERS INSIGHT -

Test­ing is done to cor­rect your code on-the-go and avoid end­ing up with a pile of er­rors on com­plet­ing your app’s de­vel­op­ment. Test­ing can get com­pli­cated when your app grows in size and APIs start to get tan­gled up, but An­gu­lar has got its own de­fined test­ing schemes. Usu­ally, two kinds of test­ing are em­ployed, unit and end-to-end test­ing (E2E). Unit test­ing is used to test in­di­vid­ual API com­po­nents, while in E2E test­ing, the work­ing of a set of com­po­nents is tested.

The usual com­po­nents of unit test­ing are de­scribe( ), be­foreEach( ) and it( ). You have to load the an­gu­lar mod­ule be­fore test­ing and be­foreEach( ) does this. Also, this func­tion

makes use of the in­jec­tor method to in­ject de­pen­den­cies. The test to be con­ducted is given in it( ). The test suite is de­scribe( ), and both be­foreEach( ) and it( ) come inside it. E2E test­ing makes use of all the above func­tions. One other func­tion used is ex­pect( ). This cre­ates ‘ex­pec­ta­tions’, which ver­ify if the par­tic­u­lar ap­pli­ca­tion's state (value of a vari­able or URL) is the same as the ex­pected val­ues.

Rec­om­mended frame­works for unit test­ing are Jas­mine and Karma, and for E2E test­ing, Pro­trac­tor is the one to go with.

Newspapers in English

Newspapers from India

© PressReader. All rights reserved.