Build Robust Web Apps in the Real World
Build Robust Web Apps in the Real World Wake. Up. And. Code. com @shahed. C
Why Unit Testing? > Getting Started > Writing and Running Tests > Mocking What’s Next?
> Nothing > Errornew to learn prone > Expensive > Slower
> Less human > Learning error curve > Faster! > Decreasing costs
Legacy New/ Improved TDD Restructure Refactor S. O. L. I. D. Design Patterns • • • SRP OCP LSP ISP DIP
Source: https: //msdn. microsoft. com/en-us/library/jj 159342. aspx
Why Unit Testing? > Getting Started > Writing and Running Tests > Mocking What’s Next?
Unit Tests Integration Tests UI Tests
Web App being tested x. Unit. net references
public test class [Fact] for public methods without parameters [Theory] and [Inline. Data] for methods with parameters
Build Solution Run Tests in Test Explorer
Note “var” keyword Verify actual result against expected result
Verify that expected view equal to returned view
Temporarily ignore tests with an optional message.
Redirect to URL? Correct Views? Correct Models? Model Populated? HTTP Code? Mock Dependencies!
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/mocks. Arent. Stubs. html
Smoke Tests New Features Edge Cases
Cost of Not Having Unit Tests Cost of Adding Unit Tests Bugs Features Expenses
Inversion of Control Dependency Injection
Views & View. Models Controllers Service Layer Repository Layer Entity Framework (ORM) SQL Server (database)
60 to 80% coverage ok?
Why Unit Testing? > Getting Started > Writing and Running Tests > Mocking What’s Next?
Email: shchowd@microsoft. com Twitter: @shahed. C
- Slides: 42