1 / 43

Automated Testing in ASP .NET Core* 1.0

Automated Testing in ASP .NET Core* 1.0. Build Robust Web Apps in the Real World. By Shahed Chowdhuri Sr. Technical Evangelist. WakeUpAndCode.com. * aka ASP.NET 5 before RC1. @shahedC. Session Objectives And Takeaways. Session Objective(s): Explain why you would need automated tests

gil-levine
Download Presentation

Automated Testing in ASP .NET Core* 1.0

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Automated Testing in ASP.NET Core* 1.0 Build Robust Web Apps in the Real World By Shahed Chowdhuri Sr. Technical Evangelist WakeUpAndCode.com * aka ASP.NET 5 before RC1 @shahedC

  2. Session Objectives And Takeaways Session Objective(s): Explain why you would need automated tests Plan a more robust software architecture Implement automated testing for web apps Automated tests provide the confidence needed to add new features to software while minimizing bugs Not having any automated tests will actually cost you more in the long run

  3. Agenda

  4. Background

  5. Manual Testing

  6. Automated Testing

  7. SRP • OCP • LSP • ISP • DIP

  8. Continuous Integration with Agile/Scrum

  9. Getting Started

  10. Unit Testing Frameworks

  11. Types of Automated Tests

  12. xUnit.net Test Extensions Click Tools  Extensions and Updates Search for xunit and install it

  13. Test Project In Solution Explorer: Create “test” folder Right-click “test” Click Add Click New Project

  14. Add New Project Select Class Library under Visual C#

  15. xUnit.net Config (Test Project)

  16. xUnit.net Config (App Project)

  17. References in Test Project Web App being tested xUnit.net references

  18. Writing and Running Tests

  19. Test Class Attributes [Fact] for public methods without parameters public test class [Theory] and [InlineData] for methods with parameters

  20. Test Explorer Build Solution Run Tests in Test Explorer

  21. Assert.Equal( ) for Returned Values Note “var” keyword Verify actual result against expected result

  22. Assert.Equal( ) for View Names Verify that expected view equal to returned view

  23. Assert.Throws<Exception>()

  24. Theory/Fact(Skip=“Reason”)] Temporarily ignore tests with an optional message.

  25. Testing Your Controllers

  26. DependencyInjection& Mocking

  27. Decouple Your Dependencies • Inversion of Control • Dependency • Injection

  28. Set Up Dependency Injection In Startup: Add namespace and dependencies • In Application Code: • Constructor Injection • Setter Injection

  29. Moq in Test Project Config

  30. Moq Reference (Test Project)

  31. Mocking Terms Reference: http://martinfowler.com/articles/mocksArentStubs.html

  32. Mocking Example HINT: Use mock.Object to get mocked object.

  33. Demo

  34. What’s Next?

  35. What About Human Testers?

  36. Cost of Unit Tests Bugs more less Features no confidence, no time! more Expenses piling up reduced

  37. Improve Your Software Architecture

  38. Functional UI Testing

  39. Code Coverage and Continuous Integration • 60 to 80% coverage ok?

  40. Integration Tests • Databases • File Systems • Network Resources • Web Requests & Responses

  41. In Review: Session Objectives And Takeaways Session Objective(s): Explain why you would need automated tests Plan a more robust software architecture Implement automated testing for web apps Automated tests provide the confidence needed to add new features to software while minimizing bugs Not having any automated tests will actually cost you more in the long run

  42. Agenda

  43. Contact Email: shchowd@microsoft.com Twitter: @shahedC

More Related