SlideShare une entreprise Scribd logo
1  sur  19
Testing Everything for ASP.NET MVC
Applications
Matt Honeycutt
@matthoneycutt
http://trycatchfail.com
Not this kind of testing…
What we’ll cover:
• Required Tools
• Testing an ASP.NET MVC controller
1) Unit Testing C#
• Required Tools
• Testing a Knockout view model
• Testing jQuery and DOM manipulation
2) Unit Testing JavaScript
• Intro to SpecsFor.Mvc
• Implementing a new feature TDD-style
3) End-to-End Testing
Heroic Support
Support
Request
•E-mail
•Website
Tracking
•See what’s waiting
•Tag and categorize
Response
•Reply via E-mail
•See conversations
Given-When-Then
Given… • a ticket
exists
When…
• a user
views the
ticket
Then…
•It displays the ticket
title
•It displays the ticket
body
•It displays the
submitter’s name
Given a ticket exists, when a user views the ticket, then it displays the ticket title, it displays
the ticket body, and it displays the submitter’s name.
Unit-Testing with C# in ASP.NET MVC
Base Class for Specs
• Built on NUnit
• Auto-mocking container
• Supports DRY testing
with Spec-style tests
• Use as little or as much
as you want
Includes Solutions to
Common Problems
• Moq – Mocking
framework
• Should – Assertion
extension methods
• ExpectedObjects –
Compare objects cleanly
Additional Helpers
• Additional assertion
extension methods
• Extensions simplify to
Moq and
ExpectedObjects
Demo: Testing an MVC Action
Given… • No state
When…
• Someone
submits a
new ticket
Then…
• It displays a
success message
• It saves the ticket
• It redirects back
to the dashboard
When someone submits a new ticket, it displays a success message, it saves the ticket, and it
redirects back to the dashboard
Another example
Given… • a ticket
exists
When…
• a user
views the
ticket
Then…
•It displays the ticket
title
•It displays the ticket
body
•It displays the
submitter’s E-mail
Given a ticket exists, when a user views the ticket, it displays the ticket title, it displays the
ticket body, and it displays the submitter’s E-mail.
Testing JavaScript with
Given-When-Then
Given…
• a ticket
view
model
When… • saving
tags
Then…
• it saves tags to
the server
• it displays a
success message
Given a ticket view model, when saving tags, it saves tags to the server, and it displays a
success message.
Jasmine Specifications
Describe…
• a ticket
view
model
Describe…
• when
saving
tags
It…
• saves tags to the
server
• displays a
success message
Given a ticket view model, when saving tags, it saves tags to the server, and it displays a
success message.
Unit-Testing a Knockout View Model
ASP.NET Application
Host
• Built on IIS Express
• Deploy and host your
app when you run your
tests
• Includes a “stub” SMTP
server
Abstraction Over
Selenium Web
Driver
• Handles browser driver
management
• Provides simplified API
for common operations
Strongly-Typed API
for Browser
Automation
• Unit-test like syntax
• Navigation and page
manipulation based on
lambda expressions
End-to-End Tests with…
Authentication
Given… • a user
exists
When…
• logging in
with valid
credentials
Then…
• it redirects
to the
dashboard
Given a user exists, when logging in with valid credentials, it redirects to the dashboard.
End-to-End Tests for ASP.NET MVC
Replying to a Ticket
Given…
• there is an
existing
ticket
When…
• when
replying to
the ticket
Then…
• it sends the response
to the submitter
• it displays the response
on the ticket
Given there is an existing ticket, when replying to a ticket, then it sends the response to the
submitter and displays the response on the ticket.
Test your client-side JavaScript
Test your server-side C#
Test your app end-to-end
Want More?
• Last session of the day, learn about cloud-enabling this app!
Come see me tomorrow!
•
Install SpecsFor and SpecsFor.Mvc
• @matthoneycutt
Ping me online:
• http://trycatchfail.com
Follow my blog:

Contenu connexe

Similaire à Testing Everything for ASP.NET MVC Applications

ASP.NET MVC 2.0
ASP.NET MVC 2.0ASP.NET MVC 2.0
ASP.NET MVC 2.0Buu Nguyen
 
How to JavaOne 2016 - Generate Customized Java 8 Code from Your Database [TUT...
How to JavaOne 2016 - Generate Customized Java 8 Code from Your Database [TUT...How to JavaOne 2016 - Generate Customized Java 8 Code from Your Database [TUT...
How to JavaOne 2016 - Generate Customized Java 8 Code from Your Database [TUT...Malin Weiss
 
JavaOne2016 - How to Generate Customized Java 8 Code from Your Database [TUT4...
JavaOne2016 - How to Generate Customized Java 8 Code from Your Database [TUT4...JavaOne2016 - How to Generate Customized Java 8 Code from Your Database [TUT4...
JavaOne2016 - How to Generate Customized Java 8 Code from Your Database [TUT4...Speedment, Inc.
 
Getting started with MVC 5 and Visual Studio 2013
Getting started with MVC 5 and Visual Studio 2013Getting started with MVC 5 and Visual Studio 2013
Getting started with MVC 5 and Visual Studio 2013Thomas Robbins
 
Web Technologies in Java EE 7
Web Technologies in Java EE 7Web Technologies in Java EE 7
Web Technologies in Java EE 7Lukáš Fryč
 
Struts 2 - Introduction
Struts 2 - Introduction Struts 2 - Introduction
Struts 2 - Introduction Hitesh-Java
 
ASP.NET MVC_Routing_Authentication_Aurhorization.pdf
ASP.NET MVC_Routing_Authentication_Aurhorization.pdfASP.NET MVC_Routing_Authentication_Aurhorization.pdf
ASP.NET MVC_Routing_Authentication_Aurhorization.pdfsetit72024
 
Session 41 - Struts 2 Introduction
Session 41 - Struts 2 IntroductionSession 41 - Struts 2 Introduction
Session 41 - Struts 2 IntroductionPawanMM
 
Struts 2 - Hibernate Integration
Struts 2 - Hibernate Integration Struts 2 - Hibernate Integration
Struts 2 - Hibernate Integration Hitesh-Java
 
Session 42 - Struts 2 Hibernate Integration
Session 42 - Struts 2 Hibernate IntegrationSession 42 - Struts 2 Hibernate Integration
Session 42 - Struts 2 Hibernate IntegrationPawanMM
 
Azure Application insights - An Introduction
Azure Application insights - An IntroductionAzure Application insights - An Introduction
Azure Application insights - An IntroductionMatthias Güntert
 

Similaire à Testing Everything for ASP.NET MVC Applications (20)

ASP.NET MVC 2.0
ASP.NET MVC 2.0ASP.NET MVC 2.0
ASP.NET MVC 2.0
 
ASP.NET MVC 3
ASP.NET MVC 3ASP.NET MVC 3
ASP.NET MVC 3
 
How to JavaOne 2016 - Generate Customized Java 8 Code from Your Database [TUT...
How to JavaOne 2016 - Generate Customized Java 8 Code from Your Database [TUT...How to JavaOne 2016 - Generate Customized Java 8 Code from Your Database [TUT...
How to JavaOne 2016 - Generate Customized Java 8 Code from Your Database [TUT...
 
JavaOne2016 - How to Generate Customized Java 8 Code from Your Database [TUT4...
JavaOne2016 - How to Generate Customized Java 8 Code from Your Database [TUT4...JavaOne2016 - How to Generate Customized Java 8 Code from Your Database [TUT4...
JavaOne2016 - How to Generate Customized Java 8 Code from Your Database [TUT4...
 
Getting started with MVC 5 and Visual Studio 2013
Getting started with MVC 5 and Visual Studio 2013Getting started with MVC 5 and Visual Studio 2013
Getting started with MVC 5 and Visual Studio 2013
 
Angular js for Beginnners
Angular js for BeginnnersAngular js for Beginnners
Angular js for Beginnners
 
IP Unit 2.pptx
IP Unit 2.pptxIP Unit 2.pptx
IP Unit 2.pptx
 
Windows 8 Metro apps and the outside world
Windows 8 Metro apps and the outside worldWindows 8 Metro apps and the outside world
Windows 8 Metro apps and the outside world
 
Web Technologies in Java EE 7
Web Technologies in Java EE 7Web Technologies in Java EE 7
Web Technologies in Java EE 7
 
Asp.Net MVC 5 in Arabic
Asp.Net MVC 5 in ArabicAsp.Net MVC 5 in Arabic
Asp.Net MVC 5 in Arabic
 
Angular js
Angular jsAngular js
Angular js
 
Struts 2 - Introduction
Struts 2 - Introduction Struts 2 - Introduction
Struts 2 - Introduction
 
ASP.NET MVC_Routing_Authentication_Aurhorization.pdf
ASP.NET MVC_Routing_Authentication_Aurhorization.pdfASP.NET MVC_Routing_Authentication_Aurhorization.pdf
ASP.NET MVC_Routing_Authentication_Aurhorization.pdf
 
Angular js
Angular jsAngular js
Angular js
 
Session 41 - Struts 2 Introduction
Session 41 - Struts 2 IntroductionSession 41 - Struts 2 Introduction
Session 41 - Struts 2 Introduction
 
Struts 2 - Hibernate Integration
Struts 2 - Hibernate Integration Struts 2 - Hibernate Integration
Struts 2 - Hibernate Integration
 
Next stop: Spring 4
Next stop: Spring 4Next stop: Spring 4
Next stop: Spring 4
 
Session 42 - Struts 2 Hibernate Integration
Session 42 - Struts 2 Hibernate IntegrationSession 42 - Struts 2 Hibernate Integration
Session 42 - Struts 2 Hibernate Integration
 
Mvc fundamental
Mvc fundamentalMvc fundamental
Mvc fundamental
 
Azure Application insights - An Introduction
Azure Application insights - An IntroductionAzure Application insights - An Introduction
Azure Application insights - An Introduction
 

Dernier

Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfOverkill Security
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusZilliz
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024The Digital Insurer
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 

Dernier (20)

Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 

Testing Everything for ASP.NET MVC Applications

  • 1. Testing Everything for ASP.NET MVC Applications Matt Honeycutt @matthoneycutt http://trycatchfail.com
  • 2. Not this kind of testing…
  • 3. What we’ll cover: • Required Tools • Testing an ASP.NET MVC controller 1) Unit Testing C# • Required Tools • Testing a Knockout view model • Testing jQuery and DOM manipulation 2) Unit Testing JavaScript • Intro to SpecsFor.Mvc • Implementing a new feature TDD-style 3) End-to-End Testing
  • 4. Heroic Support Support Request •E-mail •Website Tracking •See what’s waiting •Tag and categorize Response •Reply via E-mail •See conversations
  • 5. Given-When-Then Given… • a ticket exists When… • a user views the ticket Then… •It displays the ticket title •It displays the ticket body •It displays the submitter’s name Given a ticket exists, when a user views the ticket, then it displays the ticket title, it displays the ticket body, and it displays the submitter’s name.
  • 6. Unit-Testing with C# in ASP.NET MVC
  • 7. Base Class for Specs • Built on NUnit • Auto-mocking container • Supports DRY testing with Spec-style tests • Use as little or as much as you want Includes Solutions to Common Problems • Moq – Mocking framework • Should – Assertion extension methods • ExpectedObjects – Compare objects cleanly Additional Helpers • Additional assertion extension methods • Extensions simplify to Moq and ExpectedObjects
  • 8. Demo: Testing an MVC Action Given… • No state When… • Someone submits a new ticket Then… • It displays a success message • It saves the ticket • It redirects back to the dashboard When someone submits a new ticket, it displays a success message, it saves the ticket, and it redirects back to the dashboard
  • 9. Another example Given… • a ticket exists When… • a user views the ticket Then… •It displays the ticket title •It displays the ticket body •It displays the submitter’s E-mail Given a ticket exists, when a user views the ticket, it displays the ticket title, it displays the ticket body, and it displays the submitter’s E-mail.
  • 11. Given-When-Then Given… • a ticket view model When… • saving tags Then… • it saves tags to the server • it displays a success message Given a ticket view model, when saving tags, it saves tags to the server, and it displays a success message.
  • 12. Jasmine Specifications Describe… • a ticket view model Describe… • when saving tags It… • saves tags to the server • displays a success message Given a ticket view model, when saving tags, it saves tags to the server, and it displays a success message.
  • 14. ASP.NET Application Host • Built on IIS Express • Deploy and host your app when you run your tests • Includes a “stub” SMTP server Abstraction Over Selenium Web Driver • Handles browser driver management • Provides simplified API for common operations Strongly-Typed API for Browser Automation • Unit-test like syntax • Navigation and page manipulation based on lambda expressions End-to-End Tests with…
  • 15. Authentication Given… • a user exists When… • logging in with valid credentials Then… • it redirects to the dashboard Given a user exists, when logging in with valid credentials, it redirects to the dashboard.
  • 16. End-to-End Tests for ASP.NET MVC
  • 17. Replying to a Ticket Given… • there is an existing ticket When… • when replying to the ticket Then… • it sends the response to the submitter • it displays the response on the ticket Given there is an existing ticket, when replying to a ticket, then it sends the response to the submitter and displays the response on the ticket.
  • 18. Test your client-side JavaScript Test your server-side C# Test your app end-to-end
  • 19. Want More? • Last session of the day, learn about cloud-enabling this app! Come see me tomorrow! • Install SpecsFor and SpecsFor.Mvc • @matthoneycutt Ping me online: • http://trycatchfail.com Follow my blog: