Download - Share Point Development With Unit Testing
SHAREPOINT DEVELOPMENT
WITH UNIT TESTING
JEREMY THAKE
OBJECTIVES
To explain the 3 goals of unit testing To explain where you can unit test To describe the 3 approaches to unit
testing in SharePoint
Unit Testing
Run quickly Run on every developer machine Minimal no config
(We are not testing MS code)
Where to test?
ASP.NET Web FormsApplication Pages
Web Parts Event Receivers Feature Receivers Workflow coding activities Timer Jobs
WHAT ITS NOT!
UNIT TEST 101 SETUP
TIGHTLY COUPLED CODE
SharePoint + Mocking
Interfaces are rarely used Sealed classes Internal Constructors
TypeMock Isolator for SharePoint
MOCKING 101
NATURAL MOCKS
SharePoint Guidance
WRAPPERS & façades
REPOSITORY
MVP – Model View Presenter
What to test? TDD - lots of code when 80% is usually SharePoint
code Tests functionality and requirements work
Can cover scenarios and edge cases Missing or empty URL variable Valid URL variable syntax Existence of the specified site Missing or empty ListName variable Existence of the specified list Valid SPListItemCollection return object Null or empty SPListItemCollection return object
MOCKING LARGE AREAS OF SHAREPOINT
CONCLUSION It not easy
“Lots of code”
Benefitswhen refactoringother developers changing itenvironment dependencies reducedspeed
Doesn't stop poor quality code: list.Items.CountDispose()