Automated Testing for Dynamics CRM
Unit Testing Plug-Ins
Wael Hamze
Ramon Tebar
@CRMUG
Wael Hamze
▪ Solution Architect
▪ @WaelHamze
▪ http://www.linkedin.com/in/waelhamze
@CRMUG
Ramon Tebar
▪ Solution Architect
▪ Microsoft CRM MVP
▪ http://www.ramontebar.com
@CRMUG
Automated Testing Series
1. Unit Testing Plug-ins in Dynamics CRM 2013
2. Unit Testing Custom Workflow Activities in
Dynamics CRM 2013 [Wednesday, July 8]
3. Integration Testing Plug-Ins in Dynamics CRM
2013 [Tuesday, July 29]
4. Integration Testing Custom Workflow
Activities in Dynamics CRM 2013 [Wednesday,
August 27]
@CRMUG
Automated Testing Series
1. Unit Testing Plug-ins in Dynamics CRM 2013
▪ This session will provide you with an Introduction to Unit Testing
concepts and best practices.
▪ You will learn how to apply this to fake the Dynamics CRM plug-
in runtime to unit test Dynamics CRM plug-ins using Microsoft
Fakes.
▪ This session will also introduce you to the xRM Test Framework
and show how you can speed up the creation of your tests.
@CRMUG
Unit Testing
Dependency 1
Component
Dependency 2
Unit Tests
Mock 1 Mock 2
@CRMUG
Write Testable Code: Dependency Injection
Plugin
CRM
Service Provider
Uses
CRM
Platform
CRM
Service Provider
Creates
IServiceProviderPlugin
Uses
ImplementsCreates
@CRMUG
Microsoft Fakes
▪ Framework for isolating code under test released
with .NET 4.5
▪ Create Mock object implementations for the
required interfaces (Stub) and classes (Shim)
▪ Mock any properties and methods by creating
standard .NET delegates
▪ Invoke the Mocked properties and methods as
part of your Unit Test
@CRMUG
How to use
Microsoft Fakes
Demo
@CRMUG
Unit Test StubIServiceProvider Plugin
Create
Setup Mocks
Create
Execute
Call
Verify / Assert
Plug-In Testing Sequence
@CRMUG
How to test a plugin
using
Microsoft Fakes
Demo
@CRMUG
▪ It is definitely Possible
▪ It is definitely Helpful
▪ Too much effort using standard approach
Unit Testing Comments
@CRMUG
Demo
How to test a plugin
using
xRM Test Framework
https://xrmtestframework.codeplex.com
@CRMUG
Why Write Unit Tests?
▪ Validate all components work on their own
▪ Ability to Test Plug-ins & Custom Workflow
Activities without CRM Environment
▪ Ability to Test without Deployment
▪ Tests run much quicker
▪ Detect bugs very early and fix quickly
▪ Debug locally with Visual Studio

Automated Testing for Dynamics CRM 1 - CRMUG 2014

  • 1.
    Automated Testing forDynamics CRM Unit Testing Plug-Ins Wael Hamze Ramon Tebar
  • 2.
    @CRMUG Wael Hamze ▪ SolutionArchitect ▪ @WaelHamze ▪ http://www.linkedin.com/in/waelhamze
  • 3.
    @CRMUG Ramon Tebar ▪ SolutionArchitect ▪ Microsoft CRM MVP ▪ http://www.ramontebar.com
  • 4.
    @CRMUG Automated Testing Series 1.Unit Testing Plug-ins in Dynamics CRM 2013 2. Unit Testing Custom Workflow Activities in Dynamics CRM 2013 [Wednesday, July 8] 3. Integration Testing Plug-Ins in Dynamics CRM 2013 [Tuesday, July 29] 4. Integration Testing Custom Workflow Activities in Dynamics CRM 2013 [Wednesday, August 27]
  • 5.
    @CRMUG Automated Testing Series 1.Unit Testing Plug-ins in Dynamics CRM 2013 ▪ This session will provide you with an Introduction to Unit Testing concepts and best practices. ▪ You will learn how to apply this to fake the Dynamics CRM plug- in runtime to unit test Dynamics CRM plug-ins using Microsoft Fakes. ▪ This session will also introduce you to the xRM Test Framework and show how you can speed up the creation of your tests.
  • 6.
  • 7.
    @CRMUG Write Testable Code:Dependency Injection Plugin CRM Service Provider Uses CRM Platform CRM Service Provider Creates IServiceProviderPlugin Uses ImplementsCreates
  • 8.
    @CRMUG Microsoft Fakes ▪ Frameworkfor isolating code under test released with .NET 4.5 ▪ Create Mock object implementations for the required interfaces (Stub) and classes (Shim) ▪ Mock any properties and methods by creating standard .NET delegates ▪ Invoke the Mocked properties and methods as part of your Unit Test
  • 9.
  • 10.
    @CRMUG Unit Test StubIServiceProviderPlugin Create Setup Mocks Create Execute Call Verify / Assert Plug-In Testing Sequence
  • 11.
    @CRMUG How to testa plugin using Microsoft Fakes Demo
  • 12.
    @CRMUG ▪ It isdefinitely Possible ▪ It is definitely Helpful ▪ Too much effort using standard approach Unit Testing Comments
  • 13.
    @CRMUG Demo How to testa plugin using xRM Test Framework https://xrmtestframework.codeplex.com
  • 14.
    @CRMUG Why Write UnitTests? ▪ Validate all components work on their own ▪ Ability to Test Plug-ins & Custom Workflow Activities without CRM Environment ▪ Ability to Test without Deployment ▪ Tests run much quicker ▪ Detect bugs very early and fix quickly ▪ Debug locally with Visual Studio