Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

ASP.NET 5 & Unit Testing

4,903 views

Published on

Blog post: wakeupandcode.com/asp-net-5-unit-testing

Learn how you can build more robust web applications with automated unit testing! While there are plenty of resources for learning ASP.NET web application development, many developers are missing out on the knowledge and experience of implementing proper Unit Tests. As ASP.NET 5 gets ready for prime time, it's essential for all .NET developers to get an understanding of how to build Unit Tests for real-world applications in a cloud-first mobile-first world.

This presentation material was put together for a live audience for my in-person presentations.

Published in: Technology
  • Be the first to comment

ASP.NET 5 & Unit Testing

  1. 1. Build Robust Web Apps in the Real World @shahedC WakeUpAndCode.com
  2. 2. Why Unit Testing? > Getting Started > Writing and Running Tests > Mocking What’s Next?
  3. 3. > Nothing new to learn > Error-prone > Expensive > Slower
  4. 4. > Less human error > Faster! > Decreasing costs > Learning curve
  5. 5. Legacy New/ Improved • SRP • OCP • LSP • ISP • DIP
  6. 6. Source: https://msdn.microsoft.com/en-us/library/jj159342.aspx
  7. 7. Why Unit Testing? > Getting Started > Writing and Running Tests > Mocking What’s Next?
  8. 8. Unit Tests Integration Tests UI Tests
  9. 9. xUnit.net references Web App being tested
  10. 10. public test class [Fact] for public methods without parameters [Theory] and [InlineData] for methods with parameters
  11. 11. Build Solution Run Tests in Test Explorer
  12. 12. Verify actual result against expected result Note “var” keyword
  13. 13. Verify that expected view equal to returned view
  14. 14. Temporarily ignore tests with an optional message.
  15. 15. Correct Views? Redirect to URL? Correct Models? HTTP Code? Mock Depen- dencies! Model Populated?
  16. 16. 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
  17. 17. Smoke Tests New Features Edge Cases
  18. 18. Cost of Adding Unit Tests Cost of Not Having Unit Tests Bugs Features Expenses
  19. 19. Dependency Injection Inversion of Control
  20. 20. Views & ViewModels Controllers Service Layer Repository Layer Entity Framework (ORM) SQL Server (database)
  21. 21. 60 to 80% coverage ok?
  22. 22. Why Unit Testing? > Getting Started > Writing and Running Tests > Mocking What’s Next?
  23. 23. Email: shchowd@microsoft.com  Twitter: @shahedC

×