SlideShare una empresa de Scribd logo
1 de 43
Build Robust Web Apps in the Real World
@shahedC
WakeUpAndCode.com
* aka ASP.NET 5 before RC1
Background
> Getting Started
> Writing and Running Tests
> Dependency Injection & Mocking
What’s Next?
> Nothing
new to learn
> Error-prone
> Expensive
> Slower
> Less human
error
> Faster!
> Decreasing
costs
> Learning curve
Legacy
New/
Improved
• SRP
• OCP
• LSP
• ISP
• DIP
Unit Tests
Integration Tests
UI Tests
public test class [Fact] for public methods without parameters
[Theory] and [InlineData] for methods with parameters
Build Solution
Run Tests in Test Explorer
Verify actual result against expected result
Note “var” keyword
Verify that expected view equal to returned view
Temporarily ignore tests with an optional message.
Correct
Views?
Redirect
to URL?
Correct
Models?
HTTP
Code?
Mock
Depen-
dencies!
Model
Populated?
Dependency
Injection
Inversion of
Control
In Startup: Add namespace and dependencies
In Application Code:
• Constructor Injection
• Setter Injection
Mocks
Pre-programmed with expected results, doesn’t
actually connect to DB, behavior verification.
Fakes
Working examples, but not production-ready
(e..g in-memory database)
Stubs
Provides canned answers
http://martinfowler.com/articles/mocksArentStubs.html
Smoke
Tests
New
Features
Edge
Cases
Cost of Adding
Unit Tests
Cost of Not
Having Unit
Tests
Bugs
Features
Expenses
Views & ViewModels
Controllers
Service Layer
Repository Layer
Entity Framework (ORM)
SQL Server (database)
60 to 80% coverage ok?
• Databases
• File Systems
• Network Resources
• Web Requests & Responses
Background
> Getting Started
> Writing and Running Tests
> Dependency Injection & Mocking
What’s Next?
Email: shchowd@microsoft.com  Twitter: @shahedC

Más contenido relacionado

La actualidad más candente

Manual testing concepts course 1
Manual testing concepts course 1Manual testing concepts course 1
Manual testing concepts course 1
Raghu Kiran
 
Entity framework code first
Entity framework code firstEntity framework code first
Entity framework code first
Confiz
 
Unit Testing And Mocking
Unit Testing And MockingUnit Testing And Mocking
Unit Testing And Mocking
Joe Wilson
 

La actualidad más candente (20)

Beginners - Get Started With Unit Testing in .NET
Beginners - Get Started With Unit Testing in .NETBeginners - Get Started With Unit Testing in .NET
Beginners - Get Started With Unit Testing in .NET
 
Spring ppt
Spring pptSpring ppt
Spring ppt
 
Token Authentication in ASP.NET Core
Token Authentication in ASP.NET CoreToken Authentication in ASP.NET Core
Token Authentication in ASP.NET Core
 
PUC SE Day 2019 - SpringBoot
PUC SE Day 2019 - SpringBootPUC SE Day 2019 - SpringBoot
PUC SE Day 2019 - SpringBoot
 
How to Automate API Testing
How to Automate API TestingHow to Automate API Testing
How to Automate API Testing
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
.Net Core
.Net Core.Net Core
.Net Core
 
Manual testing concepts course 1
Manual testing concepts course 1Manual testing concepts course 1
Manual testing concepts course 1
 
Postman
PostmanPostman
Postman
 
API Test Automation
API Test Automation API Test Automation
API Test Automation
 
Spring boot
Spring bootSpring boot
Spring boot
 
Solid NodeJS with TypeScript, Jest & NestJS
Solid NodeJS with TypeScript, Jest & NestJSSolid NodeJS with TypeScript, Jest & NestJS
Solid NodeJS with TypeScript, Jest & NestJS
 
Postman Introduction
Postman IntroductionPostman Introduction
Postman Introduction
 
Entity framework code first
Entity framework code firstEntity framework code first
Entity framework code first
 
Maven Introduction
Maven IntroductionMaven Introduction
Maven Introduction
 
Unit Testing (C#)
Unit Testing (C#)Unit Testing (C#)
Unit Testing (C#)
 
An Introduction to Unit Testing
An Introduction to Unit TestingAn Introduction to Unit Testing
An Introduction to Unit Testing
 
Unit Testing And Mocking
Unit Testing And MockingUnit Testing And Mocking
Unit Testing And Mocking
 
Introduction to ASP.NET Core
Introduction to ASP.NET CoreIntroduction to ASP.NET Core
Introduction to ASP.NET Core
 
40+ tips to use Postman more efficiently
40+ tips to use Postman more efficiently40+ tips to use Postman more efficiently
40+ tips to use Postman more efficiently
 

Destacado

Destacado (20)

ASP.NET Core MVC + Web API with Overview (Post RC2)
ASP.NET Core MVC + Web API with Overview (Post RC2)ASP.NET Core MVC + Web API with Overview (Post RC2)
ASP.NET Core MVC + Web API with Overview (Post RC2)
 
ASP.NET Core 1.0 Overview: Post-RC2
ASP.NET Core 1.0 Overview: Post-RC2ASP.NET Core 1.0 Overview: Post-RC2
ASP.NET Core 1.0 Overview: Post-RC2
 
ASP.NET Core 1.0 Overview: Pre-RC2
ASP.NET Core 1.0 Overview: Pre-RC2ASP.NET Core 1.0 Overview: Pre-RC2
ASP.NET Core 1.0 Overview: Pre-RC2
 
ASP.NET Core MVC + Web API with Overview
ASP.NET Core MVC + Web API with OverviewASP.NET Core MVC + Web API with Overview
ASP.NET Core MVC + Web API with Overview
 
ASP.NET Core 1.0 Overview
ASP.NET Core 1.0 OverviewASP.NET Core 1.0 Overview
ASP.NET Core 1.0 Overview
 
Getting Started with ASP.net Core 1.0
Getting Started with ASP.net Core 1.0Getting Started with ASP.net Core 1.0
Getting Started with ASP.net Core 1.0
 
BizSpark & Azure for Startups
BizSpark & Azure for StartupsBizSpark & Azure for Startups
BizSpark & Azure for Startups
 
Xbox One Dev Mode
Xbox One Dev ModeXbox One Dev Mode
Xbox One Dev Mode
 
Xbox One Dev Mode
Xbox One Dev ModeXbox One Dev Mode
Xbox One Dev Mode
 
ASP.NET Core 1.0 Overview
ASP.NET Core 1.0 OverviewASP.NET Core 1.0 Overview
ASP.NET Core 1.0 Overview
 
Intro to HoloLens Development
Intro to HoloLens DevelopmentIntro to HoloLens Development
Intro to HoloLens Development
 
Intro to Xamarin
Intro to XamarinIntro to Xamarin
Intro to Xamarin
 
Intro to Bot Framework
Intro to Bot FrameworkIntro to Bot Framework
Intro to Bot Framework
 
Beyond static configuration
Beyond static configurationBeyond static configuration
Beyond static configuration
 
Ais powerpoint (1)
Ais powerpoint (1)Ais powerpoint (1)
Ais powerpoint (1)
 
Building Real Time Applications with ASP.NET SignalR 2.0 by Rachel Appel
Building Real Time Applications with ASP.NET SignalR 2.0 by Rachel AppelBuilding Real Time Applications with ASP.NET SignalR 2.0 by Rachel Appel
Building Real Time Applications with ASP.NET SignalR 2.0 by Rachel Appel
 
SignalR
SignalRSignalR
SignalR
 
ASP .NET Core MVC
ASP .NET Core MVCASP .NET Core MVC
ASP .NET Core MVC
 
Unity 5 Jumpstart: Kickoff
Unity 5 Jumpstart: KickoffUnity 5 Jumpstart: Kickoff
Unity 5 Jumpstart: Kickoff
 
Web App Security
Web App SecurityWeb App Security
Web App Security
 

Similar a ASP.NET Core Unit Testing

API Readiness: Visualizing and Virtualizing
API Readiness: Visualizing and VirtualizingAPI Readiness: Visualizing and Virtualizing
API Readiness: Visualizing and Virtualizing
Lorinda Brandon
 
So Your Boss Wants You to Performance Test Blackboard
So Your Boss Wants You to Performance Test BlackboardSo Your Boss Wants You to Performance Test Blackboard
So Your Boss Wants You to Performance Test Blackboard
Steve Feldman
 

Similar a ASP.NET Core Unit Testing (20)

ASP.NET 5 & Unit Testing
ASP.NET 5 & Unit TestingASP.NET 5 & Unit Testing
ASP.NET 5 & Unit Testing
 
ASP.NET & Unit Testing
ASP.NET & Unit TestingASP.NET & Unit Testing
ASP.NET & Unit Testing
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
API Driven Design
API Driven DesignAPI Driven Design
API Driven Design
 
API Readiness: Visualizing and Virtualizing
API Readiness: Visualizing and VirtualizingAPI Readiness: Visualizing and Virtualizing
API Readiness: Visualizing and Virtualizing
 
WSO2Con EU 2015: API Readiness: Is Your API Ready for Primetime?
WSO2Con EU 2015: API Readiness: Is Your API Ready for Primetime?WSO2Con EU 2015: API Readiness: Is Your API Ready for Primetime?
WSO2Con EU 2015: API Readiness: Is Your API Ready for Primetime?
 
Tools for Software Testing
Tools for Software TestingTools for Software Testing
Tools for Software Testing
 
DevOps on AWS: Deep Dive on Continuous Delivery and the AWS Developer Tools
DevOps on AWS: Deep Dive on Continuous Delivery and the AWS Developer ToolsDevOps on AWS: Deep Dive on Continuous Delivery and the AWS Developer Tools
DevOps on AWS: Deep Dive on Continuous Delivery and the AWS Developer Tools
 
Automated Testing of Web Applications
Automated Testing of Web ApplicationsAutomated Testing of Web Applications
Automated Testing of Web Applications
 
Helpful Automation Techniques - Selenium Camp 2014
Helpful Automation Techniques - Selenium Camp 2014Helpful Automation Techniques - Selenium Camp 2014
Helpful Automation Techniques - Selenium Camp 2014
 
DevOps for AI Apps
DevOps for AI AppsDevOps for AI Apps
DevOps for AI Apps
 
Lecture #6. automation testing (andrey oleynik)
Lecture #6. automation testing (andrey oleynik)Lecture #6. automation testing (andrey oleynik)
Lecture #6. automation testing (andrey oleynik)
 
Web 2.0 Development with IBM DB2
Web 2.0 Development with IBM DB2Web 2.0 Development with IBM DB2
Web 2.0 Development with IBM DB2
 
So Your Boss Wants You to Performance Test Blackboard
So Your Boss Wants You to Performance Test BlackboardSo Your Boss Wants You to Performance Test Blackboard
So Your Boss Wants You to Performance Test Blackboard
 
Improving The Quality of Existing Software
Improving The Quality of Existing SoftwareImproving The Quality of Existing Software
Improving The Quality of Existing Software
 
Testing for Logic App Solutions | Integration Monday
Testing for Logic App Solutions | Integration MondayTesting for Logic App Solutions | Integration Monday
Testing for Logic App Solutions | Integration Monday
 
Sap inside track Munich 2017
Sap inside track Munich 2017Sap inside track Munich 2017
Sap inside track Munich 2017
 
Introduction to cypress in Angular (Chinese)
Introduction to cypress in Angular (Chinese)Introduction to cypress in Angular (Chinese)
Introduction to cypress in Angular (Chinese)
 
Loopt unit test experiences
Loopt unit test experiencesLoopt unit test experiences
Loopt unit test experiences
 
ALZAMER_Ahmad
ALZAMER_AhmadALZAMER_Ahmad
ALZAMER_Ahmad
 

Más de Shahed Chowdhuri

Más de Shahed Chowdhuri (20)

ASP.NET Core 2.1: The Future of Web Apps
ASP.NET Core 2.1: The Future of Web AppsASP.NET Core 2.1: The Future of Web Apps
ASP.NET Core 2.1: The Future of Web Apps
 
ASP.NET Core 2.1: The Future of Web Apps
ASP.NET Core 2.1: The Future of Web AppsASP.NET Core 2.1: The Future of Web Apps
ASP.NET Core 2.1: The Future of Web Apps
 
Cloud-Backed Mixed Reality: HoloLens & Azure Cognitive Services
Cloud-Backed Mixed Reality: HoloLens & Azure Cognitive ServicesCloud-Backed Mixed Reality: HoloLens & Azure Cognitive Services
Cloud-Backed Mixed Reality: HoloLens & Azure Cognitive Services
 
ASP.NET Core 2.1: The Future of Web Apps
ASP.NET Core 2.1: The Future of Web AppsASP.NET Core 2.1: The Future of Web Apps
ASP.NET Core 2.1: The Future of Web Apps
 
Cloud-Backed Mixed Reality with HoloLens & Azure Cognitive Services
Cloud-Backed Mixed Reality with HoloLens & Azure Cognitive ServicesCloud-Backed Mixed Reality with HoloLens & Azure Cognitive Services
Cloud-Backed Mixed Reality with HoloLens & Azure Cognitive Services
 
Microsoft Cognitive Services
Microsoft Cognitive ServicesMicrosoft Cognitive Services
Microsoft Cognitive Services
 
Intro to Bot Framework v3 with DB
Intro to Bot Framework v3 with DBIntro to Bot Framework v3 with DB
Intro to Bot Framework v3 with DB
 
Game On with Windows & Xbox One @ .NET Conf UY
Game On with Windows & Xbox One @ .NET Conf UYGame On with Windows & Xbox One @ .NET Conf UY
Game On with Windows & Xbox One @ .NET Conf UY
 
Game On with Windows & Xbox One!
Game On with Windows & Xbox One!Game On with Windows & Xbox One!
Game On with Windows & Xbox One!
 
Going Serverless with Azure Functions
Going Serverless with Azure FunctionsGoing Serverless with Azure Functions
Going Serverless with Azure Functions
 
ASP.NET Core 2.0: The Future of Web Apps
ASP.NET Core 2.0: The Future of Web AppsASP.NET Core 2.0: The Future of Web Apps
ASP.NET Core 2.0: The Future of Web Apps
 
Azure for Hackathons
Azure for HackathonsAzure for Hackathons
Azure for Hackathons
 
Intro to Xamarin: Cross-Platform Mobile Application Development
Intro to Xamarin: Cross-Platform Mobile Application DevelopmentIntro to Xamarin: Cross-Platform Mobile Application Development
Intro to Xamarin: Cross-Platform Mobile Application Development
 
Xbox One Dev Mode
Xbox One Dev ModeXbox One Dev Mode
Xbox One Dev Mode
 
What's New at Microsoft?
What's New at Microsoft?What's New at Microsoft?
What's New at Microsoft?
 
Capture the Cloud with Azure
Capture the Cloud with AzureCapture the Cloud with Azure
Capture the Cloud with Azure
 
Intro to HoloLens Development + Windows Mixed Reality
Intro to HoloLens Development + Windows Mixed RealityIntro to HoloLens Development + Windows Mixed Reality
Intro to HoloLens Development + Windows Mixed Reality
 
Intro to Bot Framework v3
Intro to Bot Framework v3Intro to Bot Framework v3
Intro to Bot Framework v3
 
Azure: PaaS or IaaS
Azure: PaaS or IaaSAzure: PaaS or IaaS
Azure: PaaS or IaaS
 
ASP.NET Core MVC + Web API with Overview
ASP.NET Core MVC + Web API with OverviewASP.NET Core MVC + Web API with Overview
ASP.NET Core MVC + Web API with Overview
 

Último

+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...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Último (20)

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
 
+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...
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
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...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
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...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
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
 
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
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
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
 
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
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 

ASP.NET Core Unit Testing

Notas del editor

  1. Title Page: Automated Testing in ASP .NET Core* 1.0 Build Robust Web Apps in the Real World * aka ASP.NET 5 before RC1 By Shahed Chowdhuri Senior Technical Evangelist @ Microsoft Blog: WakeUpAndCode.com Twitter: @shahedC
  2. Agenda
  3. Introduction
  4. Introduction
  5. Introduction
  6. Introduction
  7. Introduction
  8. Agenda
  9. Contact Microsoft email: shchowd@microsoft.com Personal Twitter: @shahedC Dev Blog: WakeUpAndCode.com