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 Kno...
Heroic Support
Support
Request
•E-mail
•Website
Tracking
•See what’s waiting
•Tag and categorize
Response
•Reply via E-mai...
Given-When-Then
Given… • a ticket
exists
When…
• a user
views the
ticket
Then…
•It displays the ticket
title
•It displays ...
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 littl...
Demo: Testing an MVC Action
Given… • No state
When…
• Someone
submits a
new ticket
Then…
• It displays a
success message
•...
Another example
Given… • a ticket
exists
When…
• a user
views the
ticket
Then…
•It displays the ticket
title
•It displays ...
Testing JavaScript with
Given-When-Then
Given…
• a ticket
view
model
When… • saving
tags
Then…
• it saves tags to
the server
• it displays a
succe...
Jasmine Specifications
Describe…
• a ticket
view
model
Describe…
• when
saving
tags
It…
• saves tags to the
server
• displ...
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” SMT...
Authentication
Given… • a user
exists
When…
• logging in
with valid
credentials
Then…
• it redirects
to the
dashboard
Give...
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 respons...
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 Sp...
Upcoming SlideShare
Loading in …5
×

Testing Everything for ASP.NET MVC Applications

3,558 views

Published on

From CodeStock 2013 - There are many kinds of testing for ASP.NET MVC applications. Find out about unit testing JavaScript with Jasmine, unit testing C# with SpecsFor, and end-to-end testing all the pieces together with SpecsFor.Mvc.

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
3,558
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
18
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Testing Everything for ASP.NET MVC Applications

  1. 1. Testing Everything for ASP.NET MVC Applications Matt Honeycutt @matthoneycutt http://trycatchfail.com
  2. 2. Not this kind of testing…
  3. 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. 4. Heroic Support Support Request •E-mail •Website Tracking •See what’s waiting •Tag and categorize Response •Reply via E-mail •See conversations
  5. 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. 6. Unit-Testing with C# in ASP.NET MVC
  7. 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. 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. 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.
  10. 10. Testing JavaScript with
  11. 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. 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.
  13. 13. Unit-Testing a Knockout View Model
  14. 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. 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. 16. End-to-End Tests for ASP.NET MVC
  17. 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. 18. Test your client-side JavaScript Test your server-side C# Test your app end-to-end
  19. 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:

×