Se ha denunciado esta presentación.
Utilizamos tu perfil de LinkedIn y tus datos de actividad para personalizar los anuncios y mostrarte publicidad más relevante. Puedes cambiar tus preferencias de publicidad en cualquier momento.

Angular Unit Testing

671 visualizaciones

Publicado el

NgIndia Angular Unit Testing Slides

Publicado en: Tecnología
  • Inicia sesión para ver los comentarios

Angular Unit Testing

  1. 1. Angular Unit Testing Shailendra Chauhan Founder & CEO - Dot Net Tricks #ngIndia Feb 24, 2018 Microsoft MVP ng-India
  2. 2. • What is Unit Testing? • Angular CLI Setup • Angular Testing Tools • Jasmine Test Spec • Setup and Teardown • Testing A Simple Component • Debugging and Code Coverage • Testing A Component with Template and Dependencies • Testing Http Service Agenda
  3. 3. • A unit testing is a method, where each unit or component of a software is tested to determine whether it is fit for use or not • A single unit is any block of code (i.e. function or class) that has one and only one responsibility • A function might have multiple unit tests according to the uses and output of the function What is Unit Testing?
  4. 4. Angular CLI setup Node 6.9+ npm install -g @angular/cli Angular CLI ng new appName Create New Project ng test Run Test
  5. 5. Angular Testing Tools Test Runner Karma Test Framework Jasmine Test Utilities Angular (TestBed, ComponentFixture)
  6. 6. Jasmine Test Spec describe(str, fn) • A Test Suite • Contains Test Specs it(str, fn) • A Test Spec • Contains 1 or more test expectations expect(actual) • An expected piece of behavior matcher(expected) • Does a boolean comparison • toEqual, toContain, toBeNull
  7. 7. Setup and Teardown(cleaning up) beforeAll() • Called once, before all the specs in a test suite run beforeEach() • Called before each test spec run afterAll() • Called once, after all the specs in a test suite finished afterEach() • Called after each test spec run
  8. 8. Testing A Simple Component
  9. 9. Debugging
  10. 10. Code Coverage
  11. 11. Testing A Component with Template
  12. 12. Testing A Component with Dependencies
  13. 13. Testing Http Service
  14. 14. Skill Challenge
  15. 15. Thanks!