{"id":387,"date":"2017-04-25T20:56:20","date_gmt":"2017-04-25T20:56:20","guid":{"rendered":"http:\/\/www.toponecrm.com\/blog\/?p=387"},"modified":"2017-04-26T21:51:08","modified_gmt":"2017-04-26T21:51:08","slug":"unit-testing-is-important-but-where-do-i-start","status":"publish","type":"post","link":"https:\/\/toponecrm.com\/blog\/crm\/unit-testing-is-important-but-where-do-i-start\/","title":{"rendered":"Unit testing is important but&#8230; where do I start?"},"content":{"rendered":"<p>If you have attended the increasingly popular <a href=\"http:\/\/crmsaturday.com\" target=\"_blank\" rel=\"noopener noreferrer\">CRM Saturday<\/a> conference, you probably gained some valuable insights around the key aspects of delivering successful CRM implementations, and how to overcome the main challenges one may face during the implementation.<\/p>\n<p>If not, I encourage you to visit the <a href=\"http:\/\/crmsaturday.com\" target=\"_blank\" rel=\"noopener noreferrer\">web site<\/a>, it has\u00a0great speakers, great content, and lots of networking opportunities&#8230; not to mention is one of the few Dynamics events out there where attendance is 100% <strong>free<\/strong>.<\/p>\n<p>Two of the sessions were around test automation\u00a0and how to implement a true DevOps strategy for Dynamics CRM, two key areas and best practices to increase the overall quality and healthiness of your CRM implementation, which, in turn, would give you the following\u00a0benefits:<\/p>\n<ul>\n<li>\u00a0 \u00a0 Turning your customers into even more happy customers \u00a0(external)<\/li>\n<li>\u00a0 \u00a0 Making your\u00a0colleagues a bit less stressed because of regression \/ production bugs will be reduced (internal)<\/li>\n<\/ul>\n<p>If you are still not convinced about why your team should unit test your code, <a href=\"https:\/\/dynamicsvalue.com\/blog\/crm-saturday-dublin-2017\" target=\"_blank\" rel=\"noopener noreferrer\">here&#8217;s another blog post<\/a> with the slides of the test automation presentation.<\/p>\n<p>Once your team realises how important unit testing is, the next immediate question probably is:<\/p>\n<ul>\n<li>\n<blockquote><p>&#8220;Ok, I have an implementation which has been running for years , and I have a bunch of existing code, not tested. At the same time, I have a limited set of resources and trying to unit test everything would be mad&#8230; where do I start?&#8221;<\/p><\/blockquote>\n<\/li>\n<\/ul>\n<p>Ideally, one should achieve a code coverage above\u00a090%, but if you have limited resources, my advice would be: the <strong>80\/20 rule<\/strong>.<\/p>\n<p>Try to find the <strong>20% of your code<\/strong> which represents <strong>at least the 80% of the total number of executions<\/strong> or executed time, just because if there is a bug in there, then it is<strong>\u00a0likely to affect<\/strong> <strong>more users<\/strong> than a piece of code which is executed from time to time only (this might be actually more complex as maybe something than just runs from time to time may have a bigger impact based on a million different variables&#8230; but I hope you get the idea).<\/p>\n<p>The next question might be&#8230;. <strong>how to measure it?<\/strong><\/p>\n<p>Well, it turns out, from a plugin \/ codeactivity perspective, you could extract that information from the System Jobs entity rather easily.<\/p>\n<p>Every time a plugin \/ workflow is executed, a new entry in that table is created, with the Created On, Completed On, fields etc, so you could actually measure how much time a single workflow \/ plugin execution took. If you have an On-Premise installation, then that is just a SQL query with some groupings, if On-Line, then a data extract plus some Excel manipulation magic should be enough too or&#8230; make use of the great <a href=\"https:\/\/technet.microsoft.com\/en-us\/library\/mt763947.aspx\" target=\"_blank\" rel=\"noopener noreferrer\">Organisation Insights<\/a> feature in AppSource:<\/p>\n<p>Are you unit testing your code? If so, how did you start unit testing legacy code? Did you use a different approach? We would love to know more about your own experiences.<\/p>\n<p>Please leave a comment below.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you have attended the increasingly popular CRM Saturday conference, you probably gained some valuable insights around the key aspects of delivering successful CRM implementations, and how to overcome the main challenges one may face during the implementation. If not, I encourage you to visit the web site, it has\u00a0great speakers, great content, and lots &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/toponecrm.com\/blog\/crm\/unit-testing-is-important-but-where-do-i-start\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Unit testing is important but&#8230; where do I start?&#8221;<\/span><\/a><\/p>\n","protected":false},"author":9,"featured_media":398,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_price":"","_stock":"","_tribe_ticket_header":"","_tribe_default_ticket_provider":"","_tribe_ticket_capacity":"0","_ticket_start_date":"","_ticket_end_date":"","_tribe_ticket_show_description":"","_tribe_ticket_show_not_going":false,"_tribe_ticket_use_global_stock":"","_tribe_ticket_global_stock_level":"","_global_stock_mode":"","_global_stock_cap":"","_tribe_rsvp_for_event":"","_tribe_ticket_going_count":"","_tribe_ticket_not_going_count":"","_tribe_tickets_list":[],"_tribe_ticket_has_attendee_info_fields":false},"categories":[3,15,16,17,18,21,9,10,11,26],"tags":[],"ticketed":false,"_links":{"self":[{"href":"https:\/\/toponecrm.com\/blog\/wp-json\/wp\/v2\/posts\/387"}],"collection":[{"href":"https:\/\/toponecrm.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/toponecrm.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/toponecrm.com\/blog\/wp-json\/wp\/v2\/users\/9"}],"replies":[{"embeddable":true,"href":"https:\/\/toponecrm.com\/blog\/wp-json\/wp\/v2\/comments?post=387"}],"version-history":[{"count":11,"href":"https:\/\/toponecrm.com\/blog\/wp-json\/wp\/v2\/posts\/387\/revisions"}],"predecessor-version":[{"id":399,"href":"https:\/\/toponecrm.com\/blog\/wp-json\/wp\/v2\/posts\/387\/revisions\/399"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/toponecrm.com\/blog\/wp-json\/wp\/v2\/media\/398"}],"wp:attachment":[{"href":"https:\/\/toponecrm.com\/blog\/wp-json\/wp\/v2\/media?parent=387"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/toponecrm.com\/blog\/wp-json\/wp\/v2\/categories?post=387"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/toponecrm.com\/blog\/wp-json\/wp\/v2\/tags?post=387"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}