Why Unit Testing?

Why Unit Testing?

#FakeXrmEasy TDD for Dynamics made simple Hi! @jordimontana

jordimontana82 Why Unit Testing? 1. Cost

1. Epic Bugs: Space Bugs 1. Epic Bugs: Space Bugs In 1996, first ESAs Ariane-5

mission 1. Epic Bugs: Space Bugs In 1996, first ESAs Ariane-5 mission

> $370 Million project 1. Epic Bugs: Space Bugs In 1996, first ESAs Ariane-5

mission > $370 Million project which blew up in 40 secs due to an integer overflow

2. Epic Bugs: Space Bugs In 1999, NASAs Mars Climate Orbiter

$ 320 Million Project 2. Epic Bugs: Space Bugs In 1999, NASAs Mars Climate Orbiter

$ 320 Million Project burned up by a unit of measure conversion issue 3 Epic Bugs: Financial

$440 Million 3 Epic Bugs: Financial Bankrupt

in 45 mins Bugs have consequences both external and internal

Bugs have consequences both external and internal 2. External implications Brand

Brand implications Brand implications 3. Internal implications

Pain or can you sleep at night? Unit testing gives us automated

regression testing. It does so during development, before deploy, functional testing, UAT, Staging and,

of course, Production. Unit Tests vs UI / Api Testing Why Unit Testing vs

- Fast - Reliable - Isolation Why Unit Testing vs - Is something

broken? - What exactly? - Where? Unit testing cons - Is not gonna find

new bugs for us - Not for high level testing like UI or E2E tests Thats why we need

testers! So that we can create new unit tests for the bugs they raise! Bug = Missing Unit

Test Large projects and changes - 500+ Custom entities - 80+ Plugins

- 540+ Plugin Steps - 780+ Workflows Large projects and changes - Web portals

- SSIS packages + SSRS Reports - GIS, MDS, Mobile apps, Unit + integration tests provide a sustainable approach to

change management. Why FakeXrmEasy? 1. Why FakeXrmEasy?

CRM SDK is pretty much static composed of: - CRUD - Queries - Other messages

2. Why FakeXrmEasy? Prior to 2014 started doing unit testing with FakeItEasy and. - Found myself doing a lot of repetitive tasks

- and many problems Problems with existing general purpose .NET frameworks - Generic & Complex - Mocking Queries is REALLY hard

- Multiple CRM messages to mock Problem #1: Complexity var mock = new Mock(); mock.Setup(service =>

service.Create(It.IsAny())) .Callback((Entity e) => { e.Id = id; entities.Add(e); }) .Returns((Entity e) => id);

Problem #2: Mocks ignore query filters / joins etc Problem #3: A single .Execute() method with a bunch of different messages to mock

Unit testing for Dynamics 365 would be amazing if. everything was already mocked for us, by default.

So FakeXrmEasy was born in November 2014 How it Works? - 1 single ctx.GetOrganizationService() call needed.

- Query Engine: QueryExpression, LINQ, FetchXml, QueryByAttribute - Fake Messages: many implemented, but not all of them yet (pull requests pls!) Architecture Overview

IOrganizationService FakeItEasy Fake Message Executors CRUD

Query Engine In-Memory DB (this is actually way more simple than it sounds!) In-Memory DB - 2 Levels of Dictionaries

- First level indexes by Entity Name, second level indexes entity records by Id (Guid) to simulate the different CRM tables. In-Memory DB (this is actually way more simple than it sounds!)

In-Memory DB Fast! Mainly because memory is several orders of magnitude faster than disks or network. Also, because even in-memory, dictionaries gives us generally (1) algorithm complexity: Constant Access Time for CRUD operations. Given O(n) the worst case.

CRUD In-Memory DB (this is actually way more simple than it sounds!) What about the Query Engine?

Query Engine In-Memory DB (this is actually way more simple than it sounds!) CRM LINQ Provider CRM LINQ

QueryExpression In-Memory DB (Dictionaries here) What about the Query

Engine? CRM LINQ QueryExpression ???

In-Memory DB (Dictionaries here) What about the Query Engine? CRM LINQ

QueryExpression LINQ Query Translation Step

In-Memory DB (Dictionaries) What about the Query Engine? CRM LINQ

QueryByAttribute QueryExpression LINQ In-Memory DB (Dictionaries)

FetchXml What about the Query Engine? CRM LINQ

QueryByAttribute QueryExpression LINQ In-Memory DB (Dictionaries)

FetchXml To recap - 1 single ctx.GetOrganizationService() call needed. - Query Engine: QueryExpression, LINQ, FetchXml, QueryByAttribute

- Fake Messages: many implemented, but not all of them yet (pull requests pls!) FakeXrmEasy provides a sustainable and costeffective approach to facilitate change management

for Dynamics 365 Applications Any .NET app connected to an IOrganizationService

Applications - Web portals Plugins, CodeActivities, Custom Actions Console apps

Xamarin apps Script component in SSIS WPF DEMO TIME!

Thanks! @DigitalFlow @slahn @arjenst @rajyraman @ccellar @bacon1986 @daryllabar * Sorted by num of contributions

References Epic Bugs http://www.computerworld.com/article/2515483/enterprise-applications/epic-failures--11infamous-software-bugs.html https://en.wikipedia.org/wiki/Cluster_(spacecraft) https://dougseven.com/2014/04/17/knightmare-a-devops-cautionary-tale/

Testing Pyramid / TDD https://martinfowler.com/bliki/TestPyramid.html https://testing.googleblog.com/2015/04/just-say-no-to-more-end-to-end-tests.html https://www.thoughtworks.com/insights/blog/mockists-are-dead-long-live-classicists

Recently Viewed Presentations

  • Diapositiva 1

    Diapositiva 1

    Base giuridica per lo sviluppo della dimensione europea dello sport Trattato europeo di Lisbona 2009 Titolo XII Istruzione, formazione professionale, gioventù e sport Articolo 165 … L'Unione contribuisce alla promozione dei profili europei dello sport, tenendo conto delle sue specificità,...
  • Plate Tectonics - Michigan State University

    Plate Tectonics - Michigan State University

    Plate Tectonics Earth Science Essentials North Farmington High School What is Plate Tectonics Crust of the Earth FLOATS on top of the mantle. Crust is broken into slabs (plates) that MOVE, slide, collide, and spread apart.
  • Welcome To Pradhan Mantri Gramin Digital Saksharta Abhiyan

    Welcome To Pradhan Mantri Gramin Digital Saksharta Abhiyan

    The main objective of the programme is to make six crore persons in rural areas, across States/UTs, digitally literate, reaching to around 40% of rural households by covering one member from every eligible household. ... Tax Account Number (PAN) and...
  • URBAN STRUCTURE MODELS - WordPress.com

    URBAN STRUCTURE MODELS - WordPress.com

    All of the urban structure models start with the CBD in the center of the city. CONCENTRIC ZONE MODEL. ... Geographers observed that there were urban land use zones based on transportation routes, such as roads, canals, and railroads. THE...
  • Financial Counsellors Conference

    Financial Counsellors Conference

    RMIT University researchers analyzed ABS data that identifies, for the first time, the extent of economic abuse in Australia. The ABS defined economic abuse when a partner: 1. stopped or tried to stop . you knowing about or having access...
  • Issue Y2K The Great War for Talent!

    Issue Y2K The Great War for Talent!

    Tom Peters' Re-Imagine! Business Excellence in a Disruptive Age REI.500/19May2005
  • The Internet: Maturing to a Critical Infrastructure SUPERnet

    The Internet: Maturing to a Critical Infrastructure SUPERnet

    is not just faster, DSL 25 hours per week Dial-up 7.5 hours per week Users online: Broadband 78% daily newspaper 74% AM/FM radio 63% morning coffee 59% cable TV Broadband Users Value DSL % who would give up: Phone +...
  • www.smithvilleschooldistrict.net

    www.smithvilleschooldistrict.net

    AP SEMINAR ASSESSMENT. AP Seminar students are assessed with two through-course performance tasks and one end-of-course exam. The performance tasks consist of a team project and presentation, and an individual research-based essay and presentation. All three assessments are summative and...