Build Robust Web Apps in the Real WakeUpAndCode.com
Why Unit Testing? > Getting Started > Writing and Running Tests > Mocking What’s Next?
> Nothing new to learn > Error-prone > Expensive > Slower
> Less human error > Faster! > Decreasing costs > Learning curve
Legacy New/ Improved Design Patterns S.O.L.I.D.TDDRefactorRestructure SRP OCP LSP ISP DIP
Source:
Why Unit Testing? > Getting Started > Writing and Running Tests > Mocking What’s Next?
Unit TestsIntegration TestsUI Tests
xUnit.net references Web App being tested
public test class [Fact] for public methods without parameters [Theory] and [InlineData] for methods with parameters
Build Solution Run Tests in Test Explorer
Verify actual result against expected result Note “var” keyword
Verify that expected view equal to returned view
Temporarily ignore tests with an optional message.
Correct Views? Redirect to URL? Correct Models? HTTP Code? Mock Depen- dencies! Model Populated?
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
Smoke Tests New Features Edge Cases
Cost of Adding Unit Tests Cost of Not Having Unit Tests Bugs Features Expenses
Dependency Injection Inversion of Control
Views & ViewModels 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?
Twitter: