Unit testing and end-to-end testing are important for Angular applications. The document discusses various types of tests, including unit tests, integration tests, and end-to-end tests. It also covers tools for testing Angular applications, such as Jasmine for writing unit tests, Karma as a test runner, Protractor for end-to-end tests, and Angular testing utilities. The document provides recommendations on testing components and services, including how to set up tests and write tests with dependencies.
In this session, we will introduce you to the concept of unit testing and how we can add new features to our application without breaking anything. We will see how we can add unit test cases for each of our components and the importance of it.
This session aims to shed some light on an emerging test automation tool, Cypress. Cypress resolves many of the test automation problems that a QA or a dev may face in UI Web Automation testing. And after a walkthrough, we will compare cypress with Selenium as well.
Contact us:
Website: https://www.knoldus.com/
Twitter: https://twitter.com/Knolspeak?ref_src...
Facbook: https://www.facebook.com/KnoldusSoftw...
Linkedin: https://in.linkedin.com/company/knoldus
Instagram: https://www.instagram.com/knoldus_inc...
Behavior Driven development is the process of exploring, discovering, defining and driving the desired behavior of software system by using conversation, concrete examples and automated tests.
In this session, we will introduce you to the concept of unit testing and how we can add new features to our application without breaking anything. We will see how we can add unit test cases for each of our components and the importance of it.
This session aims to shed some light on an emerging test automation tool, Cypress. Cypress resolves many of the test automation problems that a QA or a dev may face in UI Web Automation testing. And after a walkthrough, we will compare cypress with Selenium as well.
Contact us:
Website: https://www.knoldus.com/
Twitter: https://twitter.com/Knolspeak?ref_src...
Facbook: https://www.facebook.com/KnoldusSoftw...
Linkedin: https://in.linkedin.com/company/knoldus
Instagram: https://www.instagram.com/knoldus_inc...
Behavior Driven development is the process of exploring, discovering, defining and driving the desired behavior of software system by using conversation, concrete examples and automated tests.
Cypress vs Selenium WebDriver: Better, Or Just Different? -- by Gil TayarApplitools
** Full webinar recording: https://youtu.be/D7vxFuwnUio **
Watch Sr. Architect Gil Tayar's special hands-on session, where he explains & demonstrates how Selenium and Cypress differ.
The session covers the following topics:
* How and why do frontend developers write tests
*Selenium architecture
*Cypress architecture
*Live Demo of Cypress - including how to write a Cypress test, and how it’s used
*How Cypress deals with flakiness
*Cypress and backdoors to development
*Visual Testing using Cypress
AngularJS is a structural framework for dynamic web apps. It lets you use HTML as your template language and lets you extend HTML's syntax to express your application's components clearly and succinctly. AngularJS's data binding and dependency injection eliminate much of the code you would otherwise have to write. And it all happens within the browser, making it an ideal partner with any server technology.
RESTful API Testing using Postman, Newman, and JenkinsQASymphony
INCLUDE AUTOMATED RESTFUL API TESTING USING POSTMAN, NEWMAN, AND JENKINS
If you’re going to automate one kind of tests at your company, API testing is the perfect place to start! It’s fast and simple to write as well as fast to execute. If your company writes an API for its software, then you understand the need and importance of testing it. In this webinar, we’ll do a live demonstration of how you can use free tools, such as Postman, Newman, and Jenkins, to enhance your software quality and security.
Elise Carmichael will cover:
Why your API tests should be included with your CI
Real examples using Postman, Newman and Jenkins + Newman
An active Q&A where you can get your automated testing questions answered, live!
To get the most out of this session:
Download these free tools prior to the webinar: Postman, Newman (along with node and npm) and Jenkins
Read up on how to parse JSON objects using javascript
*Can’t attend the webinar live? Register and we will send the recording after the webinar is over.
This presentation provides an overview of a Test Automation Framework with BDD and Cucumber. It also includes several open-source initiatives that Rhoynar Software Consulting (www.rhoynar.com) has been working on in the fields of QA Automation and DevOps. Lastly, it also includes links to some of the open-source projects that you can use right now for your work.
- Continuous Integration Infra a la OpenStack - https://github.com/Rhoynar/ci-infra
- An Email Verification Library in Java:
https://github.com/Rhoynar/EmailVerify
- Automatic Test Generation using Selenium WebDriver, Java and TestNG
https://github.com/Rhoynar/AutoTestR
- Barebones BDD and Cucumber Framework integrated with Java Maven and TestNG:
https://github.com/Rhoynar/qa-automation
Cypress vs Selenium WebDriver: Better, Or Just Different? -- by Gil TayarApplitools
** Full webinar recording: https://youtu.be/D7vxFuwnUio **
Watch Sr. Architect Gil Tayar's special hands-on session, where he explains & demonstrates how Selenium and Cypress differ.
The session covers the following topics:
* How and why do frontend developers write tests
*Selenium architecture
*Cypress architecture
*Live Demo of Cypress - including how to write a Cypress test, and how it’s used
*How Cypress deals with flakiness
*Cypress and backdoors to development
*Visual Testing using Cypress
AngularJS is a structural framework for dynamic web apps. It lets you use HTML as your template language and lets you extend HTML's syntax to express your application's components clearly and succinctly. AngularJS's data binding and dependency injection eliminate much of the code you would otherwise have to write. And it all happens within the browser, making it an ideal partner with any server technology.
RESTful API Testing using Postman, Newman, and JenkinsQASymphony
INCLUDE AUTOMATED RESTFUL API TESTING USING POSTMAN, NEWMAN, AND JENKINS
If you’re going to automate one kind of tests at your company, API testing is the perfect place to start! It’s fast and simple to write as well as fast to execute. If your company writes an API for its software, then you understand the need and importance of testing it. In this webinar, we’ll do a live demonstration of how you can use free tools, such as Postman, Newman, and Jenkins, to enhance your software quality and security.
Elise Carmichael will cover:
Why your API tests should be included with your CI
Real examples using Postman, Newman and Jenkins + Newman
An active Q&A where you can get your automated testing questions answered, live!
To get the most out of this session:
Download these free tools prior to the webinar: Postman, Newman (along with node and npm) and Jenkins
Read up on how to parse JSON objects using javascript
*Can’t attend the webinar live? Register and we will send the recording after the webinar is over.
This presentation provides an overview of a Test Automation Framework with BDD and Cucumber. It also includes several open-source initiatives that Rhoynar Software Consulting (www.rhoynar.com) has been working on in the fields of QA Automation and DevOps. Lastly, it also includes links to some of the open-source projects that you can use right now for your work.
- Continuous Integration Infra a la OpenStack - https://github.com/Rhoynar/ci-infra
- An Email Verification Library in Java:
https://github.com/Rhoynar/EmailVerify
- Automatic Test Generation using Selenium WebDriver, Java and TestNG
https://github.com/Rhoynar/AutoTestR
- Barebones BDD and Cucumber Framework integrated with Java Maven and TestNG:
https://github.com/Rhoynar/qa-automation
BigData_TP2: Design Patterns dans HadoopLilia Sfaxi
Pour accéder aux fichiers nécessaires pour faire ce TP, visitez: https://drive.google.com/folderview?id=0Bz7DokLRQvx7M2JWZEt1VHdwSE0&usp=sharing
Pour plus de contenu, Visitez http://liliasfaxi.wix.com/liliasfaxi !
Pour accéder aux fichiers nécessaires pour faire ce TP, visitez: https://drive.google.com/folderview?id=0Bz7DokLRQvx7M2JWZEt1VHdwSE0&usp=sharing
Pour plus de contenu, Visitez http://liliasfaxi.wix.com/liliasfaxi !
BigData_TP1: Initiation à Hadoop et Map-ReduceLilia Sfaxi
Pour accéder aux fichiers nécessaires pour faire ce TP, visitez: https://drive.google.com/folderview?id=0Bz7DokLRQvx7M2JWZEt1VHdwSE0&usp=sharing
Pour plus de contenu, Visitez http://liliasfaxi.wix.com/liliasfaxi !
Pour accéder aux fichiers nécessaires pour faire ce TP, visitez: https://drive.google.com/folderview?id=0Bz7DokLRQvx7M2JWZEt1VHdwSE0&usp=sharing
Pour plus de contenu, Visitez http://liliasfaxi.wix.com/liliasfaxi !
We investigate one of the most popular approaches to creating software: test driven development. From the basic understanding why tests are important to a new software development paradigm, where you start with tests and them do the implementation. We glance over different areas of testing and see how one should really do the software testing in different situation.
Agile Software Testing the Agilogy WayJordi Pradel
At Agilogy we have a curated way of testing software. In these slides we share basic Principles, Patterns and Strategies to test software in Hexagonal Architectures.
Defying the typical test pyramid, we focus our testing strategy on testing the whole domain. To do so, we avoid the abuse of mocks and stubs and, instead, we use hand-crafted test fakes that behave like their production counterparts. We make sure they actually do so by testing both the production driven adapters and their fakes with the very same test suite.
Angular Unit testing
Introduction to Angular Unit testing
Angular Test Cases are automated tests written to check the functionality of an Angular application.
These tests are designed to ensure that the application is working as expected and that all components are functioning correctly.
Angular Test Cases provide a way to quickly and accurately verify that the application is working properly.
They can also be used to quickly identify any bugs or errors that may have been introduced during development.
Why do we use Angular test cases?
Using Angular test cases is important for ensuring the quality of your application's codebase.
Test cases help to detect bugs and errors in the code quickly, so that the development team can address them and fix them before they become bigger problems.
Test cases also help to make sure that new features are implemented correctly and that existing features continue to work as expected.
Finally, using test cases can help to reduce the risk of introducing new bugs into the codebase.
Unit Testing
Testing single unit of code in isolation from the rest of the code which tests behavior of a function or class
Unit testing with Jasmine and Karma for Angular Apps!
Jasmine
Jasmine is an open-source JavaScript testing framework.
JavaScript testing framework provides building blocks to write JavaScript unit test cases so each line of JavaScript statement is properly unit tested.
It is used to test any type of JavaScript application.
Jasmine is a BDD (Behavior Driven Development)
In BDD Test are written in Non-technical language so everyone can understand it easily.
BDD manly focus on the testing the behavior of code rather than implementation.
Writing test cases with Jasmine
Test cases in Jasmine are written using the ‘describe’ and ‘it’ functions. The ‘describe’ function is used to create a suite of tests, while the ‘it’ function is used to define the individual test cases.
To create a test case, first the ‘describe’ function is used to create a suite of tests and assign it a name. Then the ‘it’ function is used to define the individual test cases within the suite.
For each test case, you define the behavior you expect from the JavaScript application. You can also use assertions to test the output of the application.
Flow of Unit Test case
The Angular testing package includes two utilities called TestBed and async.
TestBed is the main Angular utility package.
The describe container contains different blocks (it, beforeEach, xit, etc.).beforeEach runs before any other block.
Karma
Karma is a testing automation tool created by the Angular JS team.
Karma is Open source tool.
Karma is a tool made on top of NodeJS to run JavaScript test cases. This is not a testing framework like Jasmine or Mocha or Chai etc.
It only allows us to run JavaScript test cases written using testing frameworks like Jasmine.
Karma allow us to execute the test cases on any browsers.
Unit tests give developers and testers a quick way to look for logic errors in the methods of classes in Visual C#, Visual Basic, and Visual C++ projects. A unit test can be created one time and run every time that source code is changed to make sure that no bugs are introduced.
This presentation will give you a fuller understanding of unit testing in Swift, its benefits, key characteristics, mocks and stubs, dependency injection, DI patters and common mistakes one may make throughout the process.
This presentation by Andrii Gavrysh, GlobalLogic expert, was delivered at GlobalLogic Lviv iOS TechTalk on November 16, 2016.
Learn more: https://www.globallogic.com/ua/gl_news/globallogic-lviv-ios-techtalk-summary
Microsoft Fakes help you isolate the code you are testing by replacing other parts of the application with substitute code. These substitutes are called stubs and shims and are under the control of your tests. Microsoft Fakes is ideal when you need to test legacy or “legacy” code that is either restricted for refactoring or “refactoring” practically means rewriting and cost you a lot.
These slides is from a session about load testing. It starts with an introduction to non-functional testing then demonstrating the phases and criteria of load testing with K6.
iOS Practice Leaders Community Meet-up.
“Unit Testing in iOS” by Maxim Koshtenko
- why we need tests and what their use in applications’ developing on a project is;
- how one should and should not test source code;
- review of some of the most popular tools which make test-writing easier;
- how to switch to unit-testing on a project which already exists.
Play with Testing on Android - Gilang Ramadhan (Academy Content Writer at Dic...DicodingEvent
Testing merupakan (QA) quality assurance dari sebuah produk. Dalam tahap ini kita jadi tahu, bila di dalam aplikasi yang kita buat terdapat bug, eror, atau salah dalam logika kode. Sehingga testing adalah bagian terpenting pada pengembangan aplikasi.
Eror bisa kita identifikasi jauh lebih dini sebelum proses produksi. Jika terjadi kesalahan dalam tahap produksi, itu sudah melibatkan user. Tentunya kerugian di dalam tahap ini akan lebih fatal. Faktanya, biaya perbaikan sebuah aplikasi eror di tahap produksi, lebih besar dibandingkan dengan biaya pengujian sebelum produksi.
Anda akan mempelajari:
- Mengapa perlu melakukan testing
- Apa sebenarnya yang dimaksud testing
- Apa saja tools yang bisa Anda manfaatkan
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...James Anderson
Effective Application Security in Software Delivery lifecycle using Deployment Firewall and DBOM
The modern software delivery process (or the CI/CD process) includes many tools, distributed teams, open-source code, and cloud platforms. Constant focus on speed to release software to market, along with the traditional slow and manual security checks has caused gaps in continuous security as an important piece in the software supply chain. Today organizations feel more susceptible to external and internal cyber threats due to the vast attack surface in their applications supply chain and the lack of end-to-end governance and risk management.
The software team must secure its software delivery process to avoid vulnerability and security breaches. This needs to be achieved with existing tool chains and without extensive rework of the delivery processes. This talk will present strategies and techniques for providing visibility into the true risk of the existing vulnerabilities, preventing the introduction of security issues in the software, resolving vulnerabilities in production environments quickly, and capturing the deployment bill of materials (DBOM).
Speakers:
Bob Boule
Robert Boule is a technology enthusiast with PASSION for technology and making things work along with a knack for helping others understand how things work. He comes with around 20 years of solution engineering experience in application security, software continuous delivery, and SaaS platforms. He is known for his dynamic presentations in CI/CD and application security integrated in software delivery lifecycle.
Gopinath Rebala
Gopinath Rebala is the CTO of OpsMx, where he has overall responsibility for the machine learning and data processing architectures for Secure Software Delivery. Gopi also has a strong connection with our customers, leading design and architecture for strategic implementations. Gopi is a frequent speaker and well-known leader in continuous delivery and integrating security into software delivery.
DevOps and Testing slides at DASA ConnectKari Kakkonen
My and Rik Marselis slides at 30.5.2024 DASA Connect conference. We discuss about what is testing, then what is agile testing and finally what is Testing in DevOps. Finally we had lovely workshop with the participants trying to find out different ways to think about quality and testing in different parts of the DevOps infinity loop.
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Tobias Schneck
As AI technology is pushing into IT I was wondering myself, as an “infrastructure container kubernetes guy”, how get this fancy AI technology get managed from an infrastructure operational view? Is it possible to apply our lovely cloud native principals as well? What benefit’s both technologies could bring to each other?
Let me take this questions and provide you a short journey through existing deployment models and use cases for AI software. On practical examples, we discuss what cloud/on-premise strategy we may need for applying it to our own infrastructure to get it to work from an enterprise perspective. I want to give an overview about infrastructure requirements and technologies, what could be beneficial or limiting your AI use cases in an enterprise environment. An interactive Demo will give you some insides, what approaches I got already working for real.
GraphRAG is All You need? LLM & Knowledge GraphGuy Korland
Guy Korland, CEO and Co-founder of FalkorDB, will review two articles on the integration of language models with knowledge graphs.
1. Unifying Large Language Models and Knowledge Graphs: A Roadmap.
https://arxiv.org/abs/2306.08302
2. Microsoft Research's GraphRAG paper and a review paper on various uses of knowledge graphs:
https://www.microsoft.com/en-us/research/blog/graphrag-unlocking-llm-discovery-on-narrative-private-data/
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualityInflectra
In this insightful webinar, Inflectra explores how artificial intelligence (AI) is transforming software development and testing. Discover how AI-powered tools are revolutionizing every stage of the software development lifecycle (SDLC), from design and prototyping to testing, deployment, and monitoring.
Learn about:
• The Future of Testing: How AI is shifting testing towards verification, analysis, and higher-level skills, while reducing repetitive tasks.
• Test Automation: How AI-powered test case generation, optimization, and self-healing tests are making testing more efficient and effective.
• Visual Testing: Explore the emerging capabilities of AI in visual testing and how it's set to revolutionize UI verification.
• Inflectra's AI Solutions: See demonstrations of Inflectra's cutting-edge AI tools like the ChatGPT plugin and Azure Open AI platform, designed to streamline your testing process.
Whether you're a developer, tester, or QA professional, this webinar will give you valuable insights into how AI is shaping the future of software delivery.
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf91mobiles
91mobiles recently conducted a Smart TV Buyer Insights Survey in which we asked over 3,000 respondents about the TV they own, aspects they look at on a new TV, and their TV buying preferences.
Key Trends Shaping the Future of Infrastructure.pdfCheryl Hung
Keynote at DIGIT West Expo, Glasgow on 29 May 2024.
Cheryl Hung, ochery.com
Sr Director, Infrastructure Ecosystem, Arm.
The key trends across hardware, cloud and open-source; exploring how these areas are likely to mature and develop over the short and long-term, and then considering how organisations can position themselves to adapt and thrive.
Let's dive deeper into the world of ODC! Ricardo Alves (OutSystems) will join us to tell all about the new Data Fabric. After that, Sezen de Bruijn (OutSystems) will get into the details on how to best design a sturdy architecture within ODC.
Neuro-symbolic is not enough, we need neuro-*semantic*Frank van Harmelen
Neuro-symbolic (NeSy) AI is on the rise. However, simply machine learning on just any symbolic structure is not sufficient to really harvest the gains of NeSy. These will only be gained when the symbolic structures have an actual semantics. I give an operational definition of semantics as “predictable inference”.
All of this illustrated with link prediction over knowledge graphs, but the argument is general.
Accelerate your Kubernetes clusters with Varnish CachingThijs Feryn
A presentation about the usage and availability of Varnish on Kubernetes. This talk explores the capabilities of Varnish caching and shows how to use the Varnish Helm chart to deploy it to Kubernetes.
This presentation was delivered at K8SUG Singapore. See https://feryn.eu/presentations/accelerate-your-kubernetes-clusters-with-varnish-caching-k8sug-singapore-28-2024 for more details.
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
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;
});
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