SlideShare a Scribd company logo
MedTech
Dr. Lilia SFAXI
www.liliasfaxi.wix.com/liliasfaxi
Chp6- Testing Angular
Unit Testing and End-to-end Testing
1
MedTech – Mediterranean Institute of Technology
CS-Web and Mobile Development
MedTech
MedTech
Testing
• Writing tests is intended to explore and confirm the behaviour of the
application
• Testing does the following:
• Guards against changes that break existing code (“regressions”).
• Clarifies what the code does both when used as intended and when faced
with deviant conditions.
• Reveals mistakes in design and implementation.
• Tests shine a harsh light on the code from many angles.
• When a part of the application seems hard to test, the root cause is
often a design flaw, something to cure now rather than later when it
becomes expensive to fix.
2
Testing Angular
MedTech
(Some) Types of Testing
• Unit Tests
• Smallest possible unit of testing
• Cover one small unit and don’t bother about how multiple units work together.
• Fast, reliable and point in the exact direction of the bug.
• Integration Tests
• Cover multiple units.
• Point out important bugs that would show up when multiple components run
together in the application.
• End-to-end Tests
• Simulate a production like environment.
• It’s as simple as testing your application from start to finish – just like a user.
• We can run end to end tests on multiple browsers and find bugs that emerge in
certain environments / browsers – such as… Internet Explorer.
3
Testing Angular
MedTech
Tools and Technologies
• You can write and run Angular tests with a variety of tools and technologies
• Jasmine
• Behaviour-driven development framework for testing JavaScript code.
• Provides everything needed to write basic tests.
• Angular testing utilities
• Create a test environment for the Angular application code under test.
• Used to condition and control parts of the application as they interact within the Angular
environment.
• Karma
• Ideal for writing and running unit tests while developing the application.
• Can be an integral part of the project's development and continuous integration processes.
• Protractor
• Run end-to-end (e2e) tests to explore the application as users experience it.
• One process runs the real application and a second process runs protractor tests that simulate
user behaviour and assert that the application responds in the browser as expected.
4
Testing Angular
MedTech
Testing Recommandations
• Put unit test spec files in the same folder as the application source
code files they test
• Such tests are easy to find.
• You see at a glance if a part of your application lacks tests.
• Nearby tests can reveal how a part works in context.
• When you move the source (inevitable), you remember to move the test.
• When you rename the source file (inevitable), you remember to rename the
test file.
• Application integration or end-to-end specs should be defined in a
separate test folder
• As they test the interactions of multiple parts spread across folders and
modules, they don't really belong to any part in particular
5
Testing Angular
MedTech
UNIT TESTING WITH JASMINE AND KARMA
6
Testing Angular
MedTech
Unit Testing with Jasmine
• Behaviour-driven development framework for testing JavaScript code
• Does not depend on any other JavaScript frameworks
• Does not require a DOM
• Jasmine tests are a set of Test Suites each composed of a set of Test
Specs
• Call describe to define a test suite, and it to define a spec
• A spec contains one or more expectations that test the state of the code
• A spec with all true expectations is a passing spec.
• A spec with one or more false expectations is a failing spec.
• Provides the global beforeEach, afterEach, beforeAll, and afterAll
functions
• Help a test suite DRY (Don't Repeat Yourself ) up any duplicated setup
7
Testing Angular
MedTech
Unit Testing with Jasmine
8
Testing Angular
describe("A spec using beforeEach and afterEach", function() {
var foo = 0;
beforeEach(function() {
foo += 1;
});
afterEach(function() {
foo = 0;
});
it("is just a function, so it can contain any code", function() {
expect(foo).toEqual(1);
});
it("can have more than one expectation", function() {
expect(foo).toEqual(1);
expect(true).toEqual(true);
});
});
MedTech
Karma Test Runner
• Karma provides a suitable testing environment to any web developer
• browsers do not have natively a concept of loading tests files, running
them, and reporting results.
• Karma:
1.Starts a small web server to serve "client-side" javascript files to be tested
2.Serves the "client-side" javascript files with the tests (or Specs, as they're often
called)
3.Serves a custom web page that will run javascript code for the tests
4.Starts a browser to load this page
5.Reports the results of the test to the server
6.Reports the results to text files, console, etc...
9
Testing Angular
MedTech
Angular Testing Utilities
• Isolated unit tests
• Examine an instance of a class all by itself without any dependencies on
Angular or any injected values
• The tester creates a test instance of the class with new, supplying test
doubles for the constructor parameters as needed, and then probes the test
instance API surface.
• Should be written for pipes and services
• Angular Testing Utilities
• Helper functions from @angular/core/testing
• Used for components
• Contrary to isolated unit tests, they can show how components interact with
Angular, and how they interact with their own templates
10
Testing Angular
MedTech
Writing Tests
• In order to write and run unit tests:
• Create a spec file in the same folder : usually, they have the same name as the
file they are testing, with the .spec.ts extension
• Run with karma using: npm test
• Focus on the console output to see the result, that should look like this:
• [0] is the compiler output, [1] is Karma output
11
Testing Angular
MedTech
Testing a Component
• TestBed
• Most important Angular testing utility
• Creates an Angular testing module (@NgModule class) that you configure
using configureTestingModule to add importas, dependencies…
• Enables the framework to detach the tested component from its own
application module and re-attach it to the test module
• TestBed.createComponent
• Creates an instance of the component under test
• Closes the TestBed to any further configuration
• ComponentFixture
• A handle on the test environment surrounding the created component
• Provides access to the component instance itself
12
Testing Angular
MedTech
Testing a Component
• DebugElement
• Handle on the component's DOM element
• Used to query for any HTML element of the component's template
• By
• Angular testing utility that produces useful predicates
• By.css produces a standard CSS selector
• nativeElement
• Returns the queried DOM element from the DebugElement
• fixture.detectChanges
• Detects changes of the component code to trigger data bindings and propagation
• createComponent does not automatically trigger change detection, you have to
do it manually
13
Testing Angular
MedTech
Testing a Component with External Template
• TestBed.createComponent is a synchronous method, whereas the
Angular template compiler reads the external files from the system
asynchronously
• The test setup for the component must give the Angular template compiler
time to read the files
• A first beforeEach must handle asynchronous compilation (use async())
• Call the asynchronous compileComponents method to compile all the components of the
testing module
• A synchronous beforeEach containing the remaining setup steps follows the
asynchronous beforeEach.
14
Testing Angular
// async beforeEach
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ BannerComponent ], // declare the test component
})
.compileComponents(); // compile template and css
}));
MedTech
Testing a Component with Dependency
• If a component has a service dependency, it should be tested without
really calling this service
• For testing the component, a dependency must be added to the
providers, but not the real service dependency
• Provide service test doubles (also called stubs, fakes, spies or mocks)
• Get the injected service from an injector (never call the created stub)
• Proceed normally
15
Testing Angular
beforeEach(() => {
userServiceStub = {isLoggedIn: true, user: { name: 'Test User'}};
TestBed.configureTestingModule({
declarations: [ WelcomeComponent ],
providers: [ {provide: UserService, useValue: userServiceStub } ]
});
fixture = TestBed.createComponent(WelcomeComponent);
userService = TestBed.get(UserService);
de = fixture.debugElement.query(By.css('.welcome'));
el = de.nativeElement;
});
MedTech
END TO END TESTING WITH PROTRACTOR
16
Testing Angular
MedTech
End-to-End Testing with Protractor
• Protractor is a framework dedicated to end-to-end testing of Angular
applications
• It is a Node.js program that supports the Jasmine and Mocha Test frameworks
• Protractor works in conjunction with Selenium (a browser automation
framework) to provide an automated test infrastructure that can simulate a
user’s interaction with an Angular application running in a browser or mobile
device.
17
Testing Angular
MedTech
Running Protractor
• We need two things to run the tests:
• A server running our application
• An instance of a webdriver through protractor
• Use the global variable browser to navigate in the web page
• Use element and by to call an HTML element:
• callButton = element(by.tagName('button'));
• First run the pretest to update the webdriver
• When running the test, a browser will briefly appear and disappear, and
the test results will be displayed in the console
18
Testing Angular
MedTech
Dr. Lilia SFAXI
www.liliasfaxi.wix.com/liliasfaxi
References
19
• Sites
• Angular2 official documentation, https://angular.io/docs, consulted in March
2017
• Protractor, http://www.protractortest.org/#/tutorial, consulted in March
2017

More Related Content

What's hot

An Introduction to Test Driven Development
An Introduction to Test Driven Development An Introduction to Test Driven Development
An Introduction to Test Driven Development
CodeOps Technologies LLP
 
Cypress vs Selenium WebDriver: Better, Or Just Different? -- by Gil Tayar
Cypress vs Selenium WebDriver: Better, Or Just Different? -- by Gil TayarCypress vs Selenium WebDriver: Better, Or Just Different? -- by Gil Tayar
Cypress vs Selenium WebDriver: Better, Or Just Different? -- by Gil Tayar
Applitools
 
Postman & API Testing by Amber Race
Postman & API Testing by Amber RacePostman & API Testing by Amber Race
Postman & API Testing by Amber Race
Postman
 
Cypress Automation
Cypress  AutomationCypress  Automation
Cypress Automation
Susantha Pathirana
 
Postman
PostmanPostman
Angular - Chapter 1 - Introduction
 Angular - Chapter 1 - Introduction Angular - Chapter 1 - Introduction
Angular - Chapter 1 - Introduction
WebStackAcademy
 
Building blocks of Angular
Building blocks of AngularBuilding blocks of Angular
Building blocks of Angular
Knoldus Inc.
 
Introduction to Bdd and cucumber
Introduction to Bdd and cucumberIntroduction to Bdd and cucumber
Introduction to Bdd and cucumber
Nibu Baby
 
RESTful API Testing using Postman, Newman, and Jenkins
RESTful API Testing using Postman, Newman, and JenkinsRESTful API Testing using Postman, Newman, and Jenkins
RESTful API Testing using Postman, Newman, and Jenkins
QASymphony
 
e2e testing with cypress
e2e testing with cypresse2e testing with cypress
e2e testing with cypress
Tomasz Bak
 
testng
testngtestng
Cypress testing
Cypress testingCypress testing
Cypress testing
Vladyslav Romanchenko
 
Automation - web testing with selenium
Automation - web testing with seleniumAutomation - web testing with selenium
Automation - web testing with selenium
Tzirla Rozental
 
Py.test
Py.testPy.test
Py.test
soasme
 
Test Automation Framework with BDD and Cucumber
Test Automation Framework with BDD and CucumberTest Automation Framework with BDD and Cucumber
Test Automation Framework with BDD and Cucumber
Rhoynar Software Consulting
 
TypeScript - An Introduction
TypeScript - An IntroductionTypeScript - An Introduction
TypeScript - An Introduction
NexThoughts Technologies
 
Unit Testing (C#)
Unit Testing (C#)Unit Testing (C#)
Unit Testing (C#)
Prashant Cholachagudd
 
Jenkins
JenkinsJenkins
TestNG Framework
TestNG Framework TestNG Framework
TestNG Framework
Levon Apreyan
 
Test Automation Framework using Cucumber BDD overview (part 1)
Test Automation Framework using Cucumber BDD overview (part 1)Test Automation Framework using Cucumber BDD overview (part 1)
Test Automation Framework using Cucumber BDD overview (part 1)
Mindfire Solutions
 

What's hot (20)

An Introduction to Test Driven Development
An Introduction to Test Driven Development An Introduction to Test Driven Development
An Introduction to Test Driven Development
 
Cypress vs Selenium WebDriver: Better, Or Just Different? -- by Gil Tayar
Cypress vs Selenium WebDriver: Better, Or Just Different? -- by Gil TayarCypress vs Selenium WebDriver: Better, Or Just Different? -- by Gil Tayar
Cypress vs Selenium WebDriver: Better, Or Just Different? -- by Gil Tayar
 
Postman & API Testing by Amber Race
Postman & API Testing by Amber RacePostman & API Testing by Amber Race
Postman & API Testing by Amber Race
 
Cypress Automation
Cypress  AutomationCypress  Automation
Cypress Automation
 
Postman
PostmanPostman
Postman
 
Angular - Chapter 1 - Introduction
 Angular - Chapter 1 - Introduction Angular - Chapter 1 - Introduction
Angular - Chapter 1 - Introduction
 
Building blocks of Angular
Building blocks of AngularBuilding blocks of Angular
Building blocks of Angular
 
Introduction to Bdd and cucumber
Introduction to Bdd and cucumberIntroduction to Bdd and cucumber
Introduction to Bdd and cucumber
 
RESTful API Testing using Postman, Newman, and Jenkins
RESTful API Testing using Postman, Newman, and JenkinsRESTful API Testing using Postman, Newman, and Jenkins
RESTful API Testing using Postman, Newman, and Jenkins
 
e2e testing with cypress
e2e testing with cypresse2e testing with cypress
e2e testing with cypress
 
testng
testngtestng
testng
 
Cypress testing
Cypress testingCypress testing
Cypress testing
 
Automation - web testing with selenium
Automation - web testing with seleniumAutomation - web testing with selenium
Automation - web testing with selenium
 
Py.test
Py.testPy.test
Py.test
 
Test Automation Framework with BDD and Cucumber
Test Automation Framework with BDD and CucumberTest Automation Framework with BDD and Cucumber
Test Automation Framework with BDD and Cucumber
 
TypeScript - An Introduction
TypeScript - An IntroductionTypeScript - An Introduction
TypeScript - An Introduction
 
Unit Testing (C#)
Unit Testing (C#)Unit Testing (C#)
Unit Testing (C#)
 
Jenkins
JenkinsJenkins
Jenkins
 
TestNG Framework
TestNG Framework TestNG Framework
TestNG Framework
 
Test Automation Framework using Cucumber BDD overview (part 1)
Test Automation Framework using Cucumber BDD overview (part 1)Test Automation Framework using Cucumber BDD overview (part 1)
Test Automation Framework using Cucumber BDD overview (part 1)
 

Viewers also liked

Introduction au Web
Introduction au WebIntroduction au Web
Introduction au Web
Lilia Sfaxi
 
Javascript Design Patterns
Javascript Design PatternsJavascript Design Patterns
Javascript Design Patterns
Lilia Sfaxi
 
Angular
AngularAngular
Angular
Lilia Sfaxi
 
Client-side JavaScript
Client-side JavaScriptClient-side JavaScript
Client-side JavaScript
Lilia Sfaxi
 
Core JavaScript
Core JavaScriptCore JavaScript
Core JavaScript
Lilia Sfaxi
 
Server-side JS with NodeJS
Server-side JS with NodeJSServer-side JS with NodeJS
Server-side JS with NodeJS
Lilia Sfaxi
 
Mobile developement
Mobile developementMobile developement
Mobile developement
Lilia Sfaxi
 
BigData_TP5 : Neo4J
BigData_TP5 : Neo4JBigData_TP5 : Neo4J
BigData_TP5 : Neo4J
Lilia Sfaxi
 
BigData_TP2: Design Patterns dans Hadoop
BigData_TP2: Design Patterns dans HadoopBigData_TP2: Design Patterns dans Hadoop
BigData_TP2: Design Patterns dans Hadoop
Lilia Sfaxi
 
BigData_TP4 : Cassandra
BigData_TP4 : CassandraBigData_TP4 : Cassandra
BigData_TP4 : Cassandra
Lilia Sfaxi
 
BigData_TP1: Initiation à Hadoop et Map-Reduce
BigData_TP1: Initiation à Hadoop et Map-ReduceBigData_TP1: Initiation à Hadoop et Map-Reduce
BigData_TP1: Initiation à Hadoop et Map-Reduce
Lilia Sfaxi
 
BigData_TP3 : Spark
BigData_TP3 : SparkBigData_TP3 : Spark
BigData_TP3 : Spark
Lilia Sfaxi
 
BigData_Chp5: Putting it all together
BigData_Chp5: Putting it all togetherBigData_Chp5: Putting it all together
BigData_Chp5: Putting it all together
Lilia Sfaxi
 
BigData_Chp3: Data Processing
BigData_Chp3: Data ProcessingBigData_Chp3: Data Processing
BigData_Chp3: Data Processing
Lilia Sfaxi
 
BigData_Chp4: NOSQL
BigData_Chp4: NOSQLBigData_Chp4: NOSQL
BigData_Chp4: NOSQL
Lilia Sfaxi
 
BigData_Chp2: Hadoop & Map-Reduce
BigData_Chp2: Hadoop & Map-ReduceBigData_Chp2: Hadoop & Map-Reduce
BigData_Chp2: Hadoop & Map-Reduce
Lilia Sfaxi
 
BigData_Chp1: Introduction à la Big Data
BigData_Chp1: Introduction à la Big DataBigData_Chp1: Introduction à la Big Data
BigData_Chp1: Introduction à la Big Data
Lilia Sfaxi
 

Viewers also liked (17)

Introduction au Web
Introduction au WebIntroduction au Web
Introduction au Web
 
Javascript Design Patterns
Javascript Design PatternsJavascript Design Patterns
Javascript Design Patterns
 
Angular
AngularAngular
Angular
 
Client-side JavaScript
Client-side JavaScriptClient-side JavaScript
Client-side JavaScript
 
Core JavaScript
Core JavaScriptCore JavaScript
Core JavaScript
 
Server-side JS with NodeJS
Server-side JS with NodeJSServer-side JS with NodeJS
Server-side JS with NodeJS
 
Mobile developement
Mobile developementMobile developement
Mobile developement
 
BigData_TP5 : Neo4J
BigData_TP5 : Neo4JBigData_TP5 : Neo4J
BigData_TP5 : Neo4J
 
BigData_TP2: Design Patterns dans Hadoop
BigData_TP2: Design Patterns dans HadoopBigData_TP2: Design Patterns dans Hadoop
BigData_TP2: Design Patterns dans Hadoop
 
BigData_TP4 : Cassandra
BigData_TP4 : CassandraBigData_TP4 : Cassandra
BigData_TP4 : Cassandra
 
BigData_TP1: Initiation à Hadoop et Map-Reduce
BigData_TP1: Initiation à Hadoop et Map-ReduceBigData_TP1: Initiation à Hadoop et Map-Reduce
BigData_TP1: Initiation à Hadoop et Map-Reduce
 
BigData_TP3 : Spark
BigData_TP3 : SparkBigData_TP3 : Spark
BigData_TP3 : Spark
 
BigData_Chp5: Putting it all together
BigData_Chp5: Putting it all togetherBigData_Chp5: Putting it all together
BigData_Chp5: Putting it all together
 
BigData_Chp3: Data Processing
BigData_Chp3: Data ProcessingBigData_Chp3: Data Processing
BigData_Chp3: Data Processing
 
BigData_Chp4: NOSQL
BigData_Chp4: NOSQLBigData_Chp4: NOSQL
BigData_Chp4: NOSQL
 
BigData_Chp2: Hadoop & Map-Reduce
BigData_Chp2: Hadoop & Map-ReduceBigData_Chp2: Hadoop & Map-Reduce
BigData_Chp2: Hadoop & Map-Reduce
 
BigData_Chp1: Introduction à la Big Data
BigData_Chp1: Introduction à la Big DataBigData_Chp1: Introduction à la Big Data
BigData_Chp1: Introduction à la Big Data
 

Similar to Testing Angular

Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
Sergey Aganezov
 
Tools for Software Testing
Tools for Software TestingTools for Software Testing
Tools for Software Testing
Mohammed Moishin
 
Agile Software Testing the Agilogy Way
Agile Software Testing the Agilogy WayAgile Software Testing the Agilogy Way
Agile Software Testing the Agilogy Way
Jordi Pradel
 
Angular Unit testing.pptx
Angular Unit testing.pptxAngular Unit testing.pptx
Angular Unit testing.pptx
RiyaBangera
 
Into The Box 2018 | Assert control over your legacy applications
Into The Box 2018 | Assert control over your legacy applicationsInto The Box 2018 | Assert control over your legacy applications
Into The Box 2018 | Assert control over your legacy applications
Ortus Solutions, Corp
 
Ch11lect1 ud
Ch11lect1 udCh11lect1 ud
Ch11lect1 ud
Ahmet Balkan
 
Unit tests and TDD
Unit tests and TDDUnit tests and TDD
Unit tests and TDD
Roman Okolovich
 
Unit testing
Unit testingUnit testing
Unit testing
Vinod Wilson
 
Beginners overview of automated testing with Rspec
Beginners overview of automated testing with RspecBeginners overview of automated testing with Rspec
Beginners overview of automated testing with Rspec
jeffrey1ross
 
An Introduction to Unit Test Using NUnit
An Introduction to Unit Test Using NUnitAn Introduction to Unit Test Using NUnit
An Introduction to Unit Test Using NUnit
weili_at_slideshare
 
Unit Testing in Swift
Unit Testing in SwiftUnit Testing in Swift
Unit Testing in Swift
GlobalLogic Ukraine
 
Automated testing overview
Automated testing overviewAutomated testing overview
Automated testing overview
Alex Pop
 
Unit testing and mocking in Python - PyCon 2018 - Kenya
Unit testing and mocking in Python - PyCon 2018 - KenyaUnit testing and mocking in Python - PyCon 2018 - Kenya
Unit testing and mocking in Python - PyCon 2018 - Kenya
Erick M'bwana
 
Microsoft Fakes, Unit Testing the (almost) Untestable Code
Microsoft Fakes, Unit Testing the (almost) Untestable CodeMicrosoft Fakes, Unit Testing the (almost) Untestable Code
Microsoft Fakes, Unit Testing the (almost) Untestable Code
Aleksandar Bozinovski
 
Unit Tests with Microsoft Fakes
Unit Tests with Microsoft FakesUnit Tests with Microsoft Fakes
Unit Tests with Microsoft Fakes
Aleksandar Bozinovski
 
Unit Testing
Unit TestingUnit Testing
Unit Testing
Sergey Podolsky
 
Laravel Load Testing: Strategies and Tools
Laravel Load Testing: Strategies and ToolsLaravel Load Testing: Strategies and Tools
Laravel Load Testing: Strategies and Tools
Muhammad Shehata
 
Unit Tesing in iOS
Unit Tesing in iOSUnit Tesing in iOS
Unit Tesing in iOS
Ciklum Ukraine
 
Play with Testing on Android - Gilang Ramadhan (Academy Content Writer at Dic...
Play with Testing on Android - Gilang Ramadhan (Academy Content Writer at Dic...Play with Testing on Android - Gilang Ramadhan (Academy Content Writer at Dic...
Play with Testing on Android - Gilang Ramadhan (Academy Content Writer at Dic...
DicodingEvent
 
Test automation proposal
Test automation proposalTest automation proposal
Test automation proposal
Mihai-Cristian Fratila
 

Similar to Testing Angular (20)

Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Tools for Software Testing
Tools for Software TestingTools for Software Testing
Tools for Software Testing
 
Agile Software Testing the Agilogy Way
Agile Software Testing the Agilogy WayAgile Software Testing the Agilogy Way
Agile Software Testing the Agilogy Way
 
Angular Unit testing.pptx
Angular Unit testing.pptxAngular Unit testing.pptx
Angular Unit testing.pptx
 
Into The Box 2018 | Assert control over your legacy applications
Into The Box 2018 | Assert control over your legacy applicationsInto The Box 2018 | Assert control over your legacy applications
Into The Box 2018 | Assert control over your legacy applications
 
Ch11lect1 ud
Ch11lect1 udCh11lect1 ud
Ch11lect1 ud
 
Unit tests and TDD
Unit tests and TDDUnit tests and TDD
Unit tests and TDD
 
Unit testing
Unit testingUnit testing
Unit testing
 
Beginners overview of automated testing with Rspec
Beginners overview of automated testing with RspecBeginners overview of automated testing with Rspec
Beginners overview of automated testing with Rspec
 
An Introduction to Unit Test Using NUnit
An Introduction to Unit Test Using NUnitAn Introduction to Unit Test Using NUnit
An Introduction to Unit Test Using NUnit
 
Unit Testing in Swift
Unit Testing in SwiftUnit Testing in Swift
Unit Testing in Swift
 
Automated testing overview
Automated testing overviewAutomated testing overview
Automated testing overview
 
Unit testing and mocking in Python - PyCon 2018 - Kenya
Unit testing and mocking in Python - PyCon 2018 - KenyaUnit testing and mocking in Python - PyCon 2018 - Kenya
Unit testing and mocking in Python - PyCon 2018 - Kenya
 
Microsoft Fakes, Unit Testing the (almost) Untestable Code
Microsoft Fakes, Unit Testing the (almost) Untestable CodeMicrosoft Fakes, Unit Testing the (almost) Untestable Code
Microsoft Fakes, Unit Testing the (almost) Untestable Code
 
Unit Tests with Microsoft Fakes
Unit Tests with Microsoft FakesUnit Tests with Microsoft Fakes
Unit Tests with Microsoft Fakes
 
Unit Testing
Unit TestingUnit Testing
Unit Testing
 
Laravel Load Testing: Strategies and Tools
Laravel Load Testing: Strategies and ToolsLaravel Load Testing: Strategies and Tools
Laravel Load Testing: Strategies and Tools
 
Unit Tesing in iOS
Unit Tesing in iOSUnit Tesing in iOS
Unit Tesing in iOS
 
Play with Testing on Android - Gilang Ramadhan (Academy Content Writer at Dic...
Play with Testing on Android - Gilang Ramadhan (Academy Content Writer at Dic...Play with Testing on Android - Gilang Ramadhan (Academy Content Writer at Dic...
Play with Testing on Android - Gilang Ramadhan (Academy Content Writer at Dic...
 
Test automation proposal
Test automation proposalTest automation proposal
Test automation proposal
 

More from Lilia Sfaxi

chp1-Intro à l'urbanisation des SI.pdf
chp1-Intro à l'urbanisation des SI.pdfchp1-Intro à l'urbanisation des SI.pdf
chp1-Intro à l'urbanisation des SI.pdf
Lilia Sfaxi
 
Plan d'études_INSAT_2022_2023.pdf
Plan d'études_INSAT_2022_2023.pdfPlan d'études_INSAT_2022_2023.pdf
Plan d'études_INSAT_2022_2023.pdf
Lilia Sfaxi
 
Lab3-DB_Neo4j
Lab3-DB_Neo4jLab3-DB_Neo4j
Lab3-DB_Neo4j
Lilia Sfaxi
 
Lab2-DB-Mongodb
Lab2-DB-MongodbLab2-DB-Mongodb
Lab2-DB-Mongodb
Lilia Sfaxi
 
Lab1-DB-Cassandra
Lab1-DB-CassandraLab1-DB-Cassandra
Lab1-DB-Cassandra
Lilia Sfaxi
 
TP2-UML-Correction
TP2-UML-CorrectionTP2-UML-Correction
TP2-UML-Correction
Lilia Sfaxi
 
TP1-UML-Correction
TP1-UML-CorrectionTP1-UML-Correction
TP1-UML-Correction
Lilia Sfaxi
 
TP0-UML-Correction
TP0-UML-CorrectionTP0-UML-Correction
TP0-UML-Correction
Lilia Sfaxi
 
TD4-UML
TD4-UMLTD4-UML
TD4-UML
Lilia Sfaxi
 
TD4-UML-Correction
TD4-UML-CorrectionTD4-UML-Correction
TD4-UML-Correction
Lilia Sfaxi
 
TD3-UML-Séquences
TD3-UML-SéquencesTD3-UML-Séquences
TD3-UML-Séquences
Lilia Sfaxi
 
TD3-UML-Correction
TD3-UML-CorrectionTD3-UML-Correction
TD3-UML-Correction
Lilia Sfaxi
 
TD2 - UML - Correction
TD2 - UML - CorrectionTD2 - UML - Correction
TD2 - UML - Correction
Lilia Sfaxi
 
TD1 - UML - DCU
TD1 - UML - DCUTD1 - UML - DCU
TD1 - UML - DCU
Lilia Sfaxi
 
TD1-UML-correction
TD1-UML-correctionTD1-UML-correction
TD1-UML-correction
Lilia Sfaxi
 
Android - Tp1 - installation et démarrage
Android - Tp1 -   installation et démarrageAndroid - Tp1 -   installation et démarrage
Android - Tp1 - installation et démarrage
Lilia Sfaxi
 
Android - Tp2 - Elements graphiques
Android - Tp2 - Elements graphiques Android - Tp2 - Elements graphiques
Android - Tp2 - Elements graphiques
Lilia Sfaxi
 
Android - Tp3 - intents
Android - Tp3 -  intentsAndroid - Tp3 -  intents
Android - Tp3 - intents
Lilia Sfaxi
 
Android - TPBonus - web services
Android - TPBonus - web servicesAndroid - TPBonus - web services
Android - TPBonus - web services
Lilia Sfaxi
 
Android - Tp4 - graphiques avancés
Android - Tp4 - graphiques avancésAndroid - Tp4 - graphiques avancés
Android - Tp4 - graphiques avancés
Lilia Sfaxi
 

More from Lilia Sfaxi (20)

chp1-Intro à l'urbanisation des SI.pdf
chp1-Intro à l'urbanisation des SI.pdfchp1-Intro à l'urbanisation des SI.pdf
chp1-Intro à l'urbanisation des SI.pdf
 
Plan d'études_INSAT_2022_2023.pdf
Plan d'études_INSAT_2022_2023.pdfPlan d'études_INSAT_2022_2023.pdf
Plan d'études_INSAT_2022_2023.pdf
 
Lab3-DB_Neo4j
Lab3-DB_Neo4jLab3-DB_Neo4j
Lab3-DB_Neo4j
 
Lab2-DB-Mongodb
Lab2-DB-MongodbLab2-DB-Mongodb
Lab2-DB-Mongodb
 
Lab1-DB-Cassandra
Lab1-DB-CassandraLab1-DB-Cassandra
Lab1-DB-Cassandra
 
TP2-UML-Correction
TP2-UML-CorrectionTP2-UML-Correction
TP2-UML-Correction
 
TP1-UML-Correction
TP1-UML-CorrectionTP1-UML-Correction
TP1-UML-Correction
 
TP0-UML-Correction
TP0-UML-CorrectionTP0-UML-Correction
TP0-UML-Correction
 
TD4-UML
TD4-UMLTD4-UML
TD4-UML
 
TD4-UML-Correction
TD4-UML-CorrectionTD4-UML-Correction
TD4-UML-Correction
 
TD3-UML-Séquences
TD3-UML-SéquencesTD3-UML-Séquences
TD3-UML-Séquences
 
TD3-UML-Correction
TD3-UML-CorrectionTD3-UML-Correction
TD3-UML-Correction
 
TD2 - UML - Correction
TD2 - UML - CorrectionTD2 - UML - Correction
TD2 - UML - Correction
 
TD1 - UML - DCU
TD1 - UML - DCUTD1 - UML - DCU
TD1 - UML - DCU
 
TD1-UML-correction
TD1-UML-correctionTD1-UML-correction
TD1-UML-correction
 
Android - Tp1 - installation et démarrage
Android - Tp1 -   installation et démarrageAndroid - Tp1 -   installation et démarrage
Android - Tp1 - installation et démarrage
 
Android - Tp2 - Elements graphiques
Android - Tp2 - Elements graphiques Android - Tp2 - Elements graphiques
Android - Tp2 - Elements graphiques
 
Android - Tp3 - intents
Android - Tp3 -  intentsAndroid - Tp3 -  intents
Android - Tp3 - intents
 
Android - TPBonus - web services
Android - TPBonus - web servicesAndroid - TPBonus - web services
Android - TPBonus - web services
 
Android - Tp4 - graphiques avancés
Android - Tp4 - graphiques avancésAndroid - Tp4 - graphiques avancés
Android - Tp4 - graphiques avancés
 

Recently uploaded

GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
Abida Shariff
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Inflectra
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Product School
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User Group
CatarinaPereira64715
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 

Recently uploaded (20)

GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User Group
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 

Testing Angular

  • 1. MedTech Dr. Lilia SFAXI www.liliasfaxi.wix.com/liliasfaxi Chp6- Testing Angular Unit Testing and End-to-end Testing 1 MedTech – Mediterranean Institute of Technology CS-Web and Mobile Development MedTech
  • 2. MedTech Testing • Writing tests is intended to explore and confirm the behaviour of the application • Testing does the following: • Guards against changes that break existing code (“regressions”). • Clarifies what the code does both when used as intended and when faced with deviant conditions. • Reveals mistakes in design and implementation. • Tests shine a harsh light on the code from many angles. • When a part of the application seems hard to test, the root cause is often a design flaw, something to cure now rather than later when it becomes expensive to fix. 2 Testing Angular
  • 3. MedTech (Some) Types of Testing • Unit Tests • Smallest possible unit of testing • Cover one small unit and don’t bother about how multiple units work together. • Fast, reliable and point in the exact direction of the bug. • Integration Tests • Cover multiple units. • Point out important bugs that would show up when multiple components run together in the application. • End-to-end Tests • Simulate a production like environment. • It’s as simple as testing your application from start to finish – just like a user. • We can run end to end tests on multiple browsers and find bugs that emerge in certain environments / browsers – such as… Internet Explorer. 3 Testing Angular
  • 4. MedTech Tools and Technologies • You can write and run Angular tests with a variety of tools and technologies • Jasmine • Behaviour-driven development framework for testing JavaScript code. • Provides everything needed to write basic tests. • Angular testing utilities • Create a test environment for the Angular application code under test. • Used to condition and control parts of the application as they interact within the Angular environment. • Karma • Ideal for writing and running unit tests while developing the application. • Can be an integral part of the project's development and continuous integration processes. • Protractor • Run end-to-end (e2e) tests to explore the application as users experience it. • One process runs the real application and a second process runs protractor tests that simulate user behaviour and assert that the application responds in the browser as expected. 4 Testing Angular
  • 5. MedTech Testing Recommandations • Put unit test spec files in the same folder as the application source code files they test • Such tests are easy to find. • You see at a glance if a part of your application lacks tests. • Nearby tests can reveal how a part works in context. • When you move the source (inevitable), you remember to move the test. • When you rename the source file (inevitable), you remember to rename the test file. • Application integration or end-to-end specs should be defined in a separate test folder • As they test the interactions of multiple parts spread across folders and modules, they don't really belong to any part in particular 5 Testing Angular
  • 6. MedTech UNIT TESTING WITH JASMINE AND KARMA 6 Testing Angular
  • 7. MedTech Unit Testing with Jasmine • Behaviour-driven development framework for testing JavaScript code • Does not depend on any other JavaScript frameworks • Does not require a DOM • Jasmine tests are a set of Test Suites each composed of a set of Test Specs • Call describe to define a test suite, and it to define a spec • A spec contains one or more expectations that test the state of the code • A spec with all true expectations is a passing spec. • A spec with one or more false expectations is a failing spec. • Provides the global beforeEach, afterEach, beforeAll, and afterAll functions • Help a test suite DRY (Don't Repeat Yourself ) up any duplicated setup 7 Testing Angular
  • 8. MedTech Unit Testing with Jasmine 8 Testing Angular describe("A spec using beforeEach and afterEach", function() { var foo = 0; beforeEach(function() { foo += 1; }); afterEach(function() { foo = 0; }); it("is just a function, so it can contain any code", function() { expect(foo).toEqual(1); }); it("can have more than one expectation", function() { expect(foo).toEqual(1); expect(true).toEqual(true); }); });
  • 9. MedTech Karma Test Runner • Karma provides a suitable testing environment to any web developer • browsers do not have natively a concept of loading tests files, running them, and reporting results. • Karma: 1.Starts a small web server to serve "client-side" javascript files to be tested 2.Serves the "client-side" javascript files with the tests (or Specs, as they're often called) 3.Serves a custom web page that will run javascript code for the tests 4.Starts a browser to load this page 5.Reports the results of the test to the server 6.Reports the results to text files, console, etc... 9 Testing Angular
  • 10. MedTech Angular Testing Utilities • Isolated unit tests • Examine an instance of a class all by itself without any dependencies on Angular or any injected values • The tester creates a test instance of the class with new, supplying test doubles for the constructor parameters as needed, and then probes the test instance API surface. • Should be written for pipes and services • Angular Testing Utilities • Helper functions from @angular/core/testing • Used for components • Contrary to isolated unit tests, they can show how components interact with Angular, and how they interact with their own templates 10 Testing Angular
  • 11. MedTech Writing Tests • In order to write and run unit tests: • Create a spec file in the same folder : usually, they have the same name as the file they are testing, with the .spec.ts extension • Run with karma using: npm test • Focus on the console output to see the result, that should look like this: • [0] is the compiler output, [1] is Karma output 11 Testing Angular
  • 12. MedTech Testing a Component • TestBed • Most important Angular testing utility • Creates an Angular testing module (@NgModule class) that you configure using configureTestingModule to add importas, dependencies… • Enables the framework to detach the tested component from its own application module and re-attach it to the test module • TestBed.createComponent • Creates an instance of the component under test • Closes the TestBed to any further configuration • ComponentFixture • A handle on the test environment surrounding the created component • Provides access to the component instance itself 12 Testing Angular
  • 13. MedTech Testing a Component • DebugElement • Handle on the component's DOM element • Used to query for any HTML element of the component's template • By • Angular testing utility that produces useful predicates • By.css produces a standard CSS selector • nativeElement • Returns the queried DOM element from the DebugElement • fixture.detectChanges • Detects changes of the component code to trigger data bindings and propagation • createComponent does not automatically trigger change detection, you have to do it manually 13 Testing Angular
  • 14. MedTech Testing a Component with External Template • TestBed.createComponent is a synchronous method, whereas the Angular template compiler reads the external files from the system asynchronously • The test setup for the component must give the Angular template compiler time to read the files • A first beforeEach must handle asynchronous compilation (use async()) • Call the asynchronous compileComponents method to compile all the components of the testing module • A synchronous beforeEach containing the remaining setup steps follows the asynchronous beforeEach. 14 Testing Angular // async beforeEach beforeEach(async(() => { TestBed.configureTestingModule({ declarations: [ BannerComponent ], // declare the test component }) .compileComponents(); // compile template and css }));
  • 15. MedTech Testing a Component with Dependency • If a component has a service dependency, it should be tested without really calling this service • For testing the component, a dependency must be added to the providers, but not the real service dependency • Provide service test doubles (also called stubs, fakes, spies or mocks) • Get the injected service from an injector (never call the created stub) • Proceed normally 15 Testing Angular beforeEach(() => { userServiceStub = {isLoggedIn: true, user: { name: 'Test User'}}; TestBed.configureTestingModule({ declarations: [ WelcomeComponent ], providers: [ {provide: UserService, useValue: userServiceStub } ] }); fixture = TestBed.createComponent(WelcomeComponent); userService = TestBed.get(UserService); de = fixture.debugElement.query(By.css('.welcome')); el = de.nativeElement; });
  • 16. MedTech END TO END TESTING WITH PROTRACTOR 16 Testing Angular
  • 17. MedTech End-to-End Testing with Protractor • Protractor is a framework dedicated to end-to-end testing of Angular applications • It is a Node.js program that supports the Jasmine and Mocha Test frameworks • Protractor works in conjunction with Selenium (a browser automation framework) to provide an automated test infrastructure that can simulate a user’s interaction with an Angular application running in a browser or mobile device. 17 Testing Angular
  • 18. MedTech Running Protractor • We need two things to run the tests: • A server running our application • An instance of a webdriver through protractor • Use the global variable browser to navigate in the web page • Use element and by to call an HTML element: • callButton = element(by.tagName('button')); • First run the pretest to update the webdriver • When running the test, a browser will briefly appear and disappear, and the test results will be displayed in the console 18 Testing Angular
  • 19. MedTech Dr. Lilia SFAXI www.liliasfaxi.wix.com/liliasfaxi References 19 • Sites • Angular2 official documentation, https://angular.io/docs, consulted in March 2017 • Protractor, http://www.protractortest.org/#/tutorial, consulted in March 2017