SlideShare une entreprise Scribd logo
1  sur  5
Testing ASP.NET MVC Framework
Simone Chiaretta
Gian Maria Ricci
27 Giugno 2008
Testare i controller
► Fino alla Preview2 era necessario “mockare”
tutto
► Nella P3 è stato fatto refactoring del
controller.
1
[TestClass]
public class BlogControllerTest
{
[TestMethod]
public void Show()
{
BlogController controller = new BlogController();
var result = controller.Show(2010,10,11,"Titolo Post")
as ViewResult;
Assert.IsNotNull(result, "Aspettavo un view da renderizzare");
Assert.AreEqual("Titolo Post", controller.ViewData["Titolo"],
“Mi aspettavo un altro messaggio");
}
}
Altri esempi di test
► Testare strongly-typed view data
– Assert.AreEqual(expected, ((BlogData)
result.ViewData.Model).Titolo,…);
► Testare Redirect
– var result = controller.Show(…) as RedirectResult;
2
Mocking HttpContext
Q&A
4

Contenu connexe

Similaire à [Hands on] testing asp.net mvc

Presentazione Testing automatizzato
Presentazione Testing automatizzatoPresentazione Testing automatizzato
Presentazione Testing automatizzatoangelolu
 
Asp.Net MVC 3 - Il Model View Controller secondo Microsoft
Asp.Net MVC 3 - Il Model View Controller secondo MicrosoftAsp.Net MVC 3 - Il Model View Controller secondo Microsoft
Asp.Net MVC 3 - Il Model View Controller secondo MicrosoftStefano Benedetti
 
Asp.NET MVC Framework
Asp.NET MVC FrameworkAsp.NET MVC Framework
Asp.NET MVC FrameworkDotNetMarche
 
Android Test Driven Development
Android Test Driven DevelopmentAndroid Test Driven Development
Android Test Driven Developmentsazilla
 
Android Test Driven Development
Android Test Driven DevelopmentAndroid Test Driven Development
Android Test Driven Developmentsazilla
 
The Hitchhiker's Guide to testable code: semplici regole per scrivere codice ...
The Hitchhiker's Guide to testable code: semplici regole per scrivere codice ...The Hitchhiker's Guide to testable code: semplici regole per scrivere codice ...
The Hitchhiker's Guide to testable code: semplici regole per scrivere codice ...Davide Cerbo
 
ZoeFX: un framework MVC per JavaFX
ZoeFX: un framework MVC per JavaFXZoeFX: un framework MVC per JavaFX
ZoeFX: un framework MVC per JavaFXTiziano Lattisi
 
Java Unit Testing - JUnit (2)
Java Unit Testing - JUnit (2)Java Unit Testing - JUnit (2)
Java Unit Testing - JUnit (2)fgianneschi
 
Java Unit Testing - JUnit (1)
Java Unit Testing - JUnit (1)Java Unit Testing - JUnit (1)
Java Unit Testing - JUnit (1)fgianneschi
 
Java Unit Testing - In container and database testing
Java Unit Testing - In container and database testingJava Unit Testing - In container and database testing
Java Unit Testing - In container and database testingfgianneschi
 
What's New in ASP.NET 4.5 and Visual Studio 2012
What's New in ASP.NET 4.5 and Visual Studio 2012What's New in ASP.NET 4.5 and Visual Studio 2012
What's New in ASP.NET 4.5 and Visual Studio 2012Andrea Dottor
 
Googletest, tdd e mock
Googletest, tdd e mockGoogletest, tdd e mock
Googletest, tdd e mockyuroller
 
ASP.NET MVC 3 - Presentare i dati nella View
ASP.NET MVC 3 - Presentare i dati nella ViewASP.NET MVC 3 - Presentare i dati nella View
ASP.NET MVC 3 - Presentare i dati nella ViewManuel Scapolan
 
Test double - un'introduzione (PHP)
Test double - un'introduzione (PHP)Test double - un'introduzione (PHP)
Test double - un'introduzione (PHP)Carmelantonio Zolfo
 

Similaire à [Hands on] testing asp.net mvc (20)

Presentazione Testing automatizzato
Presentazione Testing automatizzatoPresentazione Testing automatizzato
Presentazione Testing automatizzato
 
Asp.Net MVC 3 - Il Model View Controller secondo Microsoft
Asp.Net MVC 3 - Il Model View Controller secondo MicrosoftAsp.Net MVC 3 - Il Model View Controller secondo Microsoft
Asp.Net MVC 3 - Il Model View Controller secondo Microsoft
 
Asp.NET MVC Framework
Asp.NET MVC FrameworkAsp.NET MVC Framework
Asp.NET MVC Framework
 
Android Test Driven Development
Android Test Driven DevelopmentAndroid Test Driven Development
Android Test Driven Development
 
Android Test Driven Development
Android Test Driven DevelopmentAndroid Test Driven Development
Android Test Driven Development
 
The Hitchhiker's Guide to testable code: semplici regole per scrivere codice ...
The Hitchhiker's Guide to testable code: semplici regole per scrivere codice ...The Hitchhiker's Guide to testable code: semplici regole per scrivere codice ...
The Hitchhiker's Guide to testable code: semplici regole per scrivere codice ...
 
MVC2: non solo tecnologia
MVC2: non solo tecnologiaMVC2: non solo tecnologia
MVC2: non solo tecnologia
 
ZoeFX: un framework MVC per JavaFX
ZoeFX: un framework MVC per JavaFXZoeFX: un framework MVC per JavaFX
ZoeFX: un framework MVC per JavaFX
 
Java Unit Testing - JUnit (2)
Java Unit Testing - JUnit (2)Java Unit Testing - JUnit (2)
Java Unit Testing - JUnit (2)
 
Java Unit Testing - JUnit (1)
Java Unit Testing - JUnit (1)Java Unit Testing - JUnit (1)
Java Unit Testing - JUnit (1)
 
Java Unit Testing - In container and database testing
Java Unit Testing - In container and database testingJava Unit Testing - In container and database testing
Java Unit Testing - In container and database testing
 
What's New in ASP.NET 4.5 and Visual Studio 2012
What's New in ASP.NET 4.5 and Visual Studio 2012What's New in ASP.NET 4.5 and Visual Studio 2012
What's New in ASP.NET 4.5 and Visual Studio 2012
 
Googletest, tdd e mock
Googletest, tdd e mockGoogletest, tdd e mock
Googletest, tdd e mock
 
Yagwto
YagwtoYagwto
Yagwto
 
Java lezione 10
Java lezione 10Java lezione 10
Java lezione 10
 
ASP.NET MVC: Full Throttle
ASP.NET MVC: Full ThrottleASP.NET MVC: Full Throttle
ASP.NET MVC: Full Throttle
 
ASP.NET MVC
ASP.NET MVCASP.NET MVC
ASP.NET MVC
 
Java lezione 16
Java lezione 16Java lezione 16
Java lezione 16
 
ASP.NET MVC 3 - Presentare i dati nella View
ASP.NET MVC 3 - Presentare i dati nella ViewASP.NET MVC 3 - Presentare i dati nella View
ASP.NET MVC 3 - Presentare i dati nella View
 
Test double - un'introduzione (PHP)
Test double - un'introduzione (PHP)Test double - un'introduzione (PHP)
Test double - un'introduzione (PHP)
 

Plus de DotNetMarche

Creare una community dal basso ed arrivare ad un'azienda milionaria - Emanue...
Creare una community dal basso ed arrivare ad un'azienda milionaria  - Emanue...Creare una community dal basso ed arrivare ad un'azienda milionaria  - Emanue...
Creare una community dal basso ed arrivare ad un'azienda milionaria - Emanue...DotNetMarche
 
Metriche per Zombie Communities: come "iniettare vita" in tribù di morti vive...
Metriche per Zombie Communities: come "iniettare vita" in tribù di morti vive...Metriche per Zombie Communities: come "iniettare vita" in tribù di morti vive...
Metriche per Zombie Communities: come "iniettare vita" in tribù di morti vive...DotNetMarche
 
UI Composition - Prism
UI Composition - PrismUI Composition - Prism
UI Composition - PrismDotNetMarche
 
Model-View-ViewModel
Model-View-ViewModelModel-View-ViewModel
Model-View-ViewModelDotNetMarche
 
Refactoring ASP.NET and beyond
Refactoring ASP.NET and beyondRefactoring ASP.NET and beyond
Refactoring ASP.NET and beyondDotNetMarche
 
Refactoring 2TheMax (con ReSharper)
Refactoring 2TheMax (con ReSharper)Refactoring 2TheMax (con ReSharper)
Refactoring 2TheMax (con ReSharper)DotNetMarche
 
Silverlight in Action
Silverlight in ActionSilverlight in Action
Silverlight in ActionDotNetMarche
 
Silverlight in Action
Silverlight in ActionSilverlight in Action
Silverlight in ActionDotNetMarche
 
Soluzioni Microsoft per l'e-Learning
Soluzioni Microsoft per l'e-LearningSoluzioni Microsoft per l'e-Learning
Soluzioni Microsoft per l'e-LearningDotNetMarche
 
Installing and Administering MOSS
Installing and Administering MOSSInstalling and Administering MOSS
Installing and Administering MOSSDotNetMarche
 
Microsoft SharePoint Server 2007 Technical Overview
Microsoft SharePoint Server 2007 Technical OverviewMicrosoft SharePoint Server 2007 Technical Overview
Microsoft SharePoint Server 2007 Technical OverviewDotNetMarche
 
Introduzione al Testing
Introduzione al TestingIntroduzione al Testing
Introduzione al TestingDotNetMarche
 
Introduzione a CardSpace
Introduzione a CardSpaceIntroduzione a CardSpace
Introduzione a CardSpaceDotNetMarche
 
Introduzione a Workflow Foundation
Introduzione a Workflow FoundationIntroduzione a Workflow Foundation
Introduzione a Workflow FoundationDotNetMarche
 
Domain Model e SOA (Service Oriented Architecture)
Domain Model e SOA (Service Oriented Architecture)Domain Model e SOA (Service Oriented Architecture)
Domain Model e SOA (Service Oriented Architecture)DotNetMarche
 

Plus de DotNetMarche (20)

Creare una community dal basso ed arrivare ad un'azienda milionaria - Emanue...
Creare una community dal basso ed arrivare ad un'azienda milionaria  - Emanue...Creare una community dal basso ed arrivare ad un'azienda milionaria  - Emanue...
Creare una community dal basso ed arrivare ad un'azienda milionaria - Emanue...
 
Metriche per Zombie Communities: come "iniettare vita" in tribù di morti vive...
Metriche per Zombie Communities: come "iniettare vita" in tribù di morti vive...Metriche per Zombie Communities: come "iniettare vita" in tribù di morti vive...
Metriche per Zombie Communities: come "iniettare vita" in tribù di morti vive...
 
WPF 4 fun
WPF 4 funWPF 4 fun
WPF 4 fun
 
UI Composition - Prism
UI Composition - PrismUI Composition - Prism
UI Composition - Prism
 
UI Composition
UI CompositionUI Composition
UI Composition
 
Model-View-ViewModel
Model-View-ViewModelModel-View-ViewModel
Model-View-ViewModel
 
WPF basics
WPF basicsWPF basics
WPF basics
 
Refactoring ASP.NET and beyond
Refactoring ASP.NET and beyondRefactoring ASP.NET and beyond
Refactoring ASP.NET and beyond
 
Refactoring 2TheMax (con ReSharper)
Refactoring 2TheMax (con ReSharper)Refactoring 2TheMax (con ReSharper)
Refactoring 2TheMax (con ReSharper)
 
jQuery Loves You
jQuery Loves YoujQuery Loves You
jQuery Loves You
 
Silverlight in Action
Silverlight in ActionSilverlight in Action
Silverlight in Action
 
Silverlight in Action
Silverlight in ActionSilverlight in Action
Silverlight in Action
 
Open XML & MOSS
Open XML & MOSSOpen XML & MOSS
Open XML & MOSS
 
Soluzioni Microsoft per l'e-Learning
Soluzioni Microsoft per l'e-LearningSoluzioni Microsoft per l'e-Learning
Soluzioni Microsoft per l'e-Learning
 
Installing and Administering MOSS
Installing and Administering MOSSInstalling and Administering MOSS
Installing and Administering MOSS
 
Microsoft SharePoint Server 2007 Technical Overview
Microsoft SharePoint Server 2007 Technical OverviewMicrosoft SharePoint Server 2007 Technical Overview
Microsoft SharePoint Server 2007 Technical Overview
 
Introduzione al Testing
Introduzione al TestingIntroduzione al Testing
Introduzione al Testing
 
Introduzione a CardSpace
Introduzione a CardSpaceIntroduzione a CardSpace
Introduzione a CardSpace
 
Introduzione a Workflow Foundation
Introduzione a Workflow FoundationIntroduzione a Workflow Foundation
Introduzione a Workflow Foundation
 
Domain Model e SOA (Service Oriented Architecture)
Domain Model e SOA (Service Oriented Architecture)Domain Model e SOA (Service Oriented Architecture)
Domain Model e SOA (Service Oriented Architecture)
 

[Hands on] testing asp.net mvc

  • 1. Testing ASP.NET MVC Framework Simone Chiaretta Gian Maria Ricci 27 Giugno 2008
  • 2. Testare i controller ► Fino alla Preview2 era necessario “mockare” tutto ► Nella P3 è stato fatto refactoring del controller. 1 [TestClass] public class BlogControllerTest { [TestMethod] public void Show() { BlogController controller = new BlogController(); var result = controller.Show(2010,10,11,"Titolo Post") as ViewResult; Assert.IsNotNull(result, "Aspettavo un view da renderizzare"); Assert.AreEqual("Titolo Post", controller.ViewData["Titolo"], “Mi aspettavo un altro messaggio"); } }
  • 3. Altri esempi di test ► Testare strongly-typed view data – Assert.AreEqual(expected, ((BlogData) result.ViewData.Model).Titolo,…); ► Testare Redirect – var result = controller.Show(…) as RedirectResult; 2