OpenSource For You

Testing

-

Testing is done to correct your code on-the-go and avoid ending up with a pile of errors on completing your app’s developmen­t. Testing can get complicate­d when your app grows in size and APIs start to get tangled up, but Angular has got its own defined testing schemes. Usually, two kinds of testing are employed, unit and end-to-end testing (E2E). Unit testing is used to test individual API components, while in E2E testing, the working of a set of components is tested.

The usual components of unit testing are describe( ), beforeEach( ) and it( ). You have to load the angular module before testing and beforeEach( ) does this. Also, this function

makes use of the injector method to inject dependenci­es. The test to be conducted is given in it( ). The test suite is describe( ), and both beforeEach( ) and it( ) come inside it. E2E testing makes use of all the above functions. One other function used is expect( ). This creates ‘expectatio­ns’, which verify if the particular applicatio­n's state (value of a variable or URL) is the same as the expected values.

Recommende­d frameworks for unit testing are Jasmine and Karma, and for E2E testing, Protractor is the one to go with.

Newspapers in English

Newspapers from India