An Overview of .NET Best Practices
Upcoming SlideShare
Loading in...5
×
 

An Overview of .NET Best Practices

on

  • 564 views

This presentation is a practical overview of many of the best practices that you can apply to your .NET projects today. We will cover a broad range of practices and principles with an emphasis on ...

This presentation is a practical overview of many of the best practices that you can apply to your .NET projects today. We will cover a broad range of practices and principles with an emphasis on tools and technologies in four key areas: build automation, continuous integration, automated testing, and code analysis. Since complex problems often require iterative solutions, this presentation looks at an iterative approach to adopting new and better practices. Through a stepwise process we’ll examine key areas to improve, how to get started and continue to grow implementation, and what might motivate folks to stick with .NET best practices.

Statistics

Views

Total Views
564
Views on SlideShare
557
Embed Views
7

Actions

Likes
0
Downloads
13
Comments
0

1 Embed 7

http://speakerrate.com 7

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • Week 1Build ScriptWrite a build script using a common build scripting tool.Rebuild AllThe entire project solutionSoup-to-nuts rebuildOne command file calls one script
  • Manual BuildsVisual Studio is NOT a Build ToolDanger ZoneInconsistencyHero Worship
  • Helpful ChangeWrite a Build ScriptConventional Scripting ToolMSBuildConventionalPart of .NETUsed by Visual Studio and TFSWidely used, lots of examplesPart of .NET Fundamentals
  • Conventional Scripting ToolNAntFree and open-sourcePopular with .NET developersWidely used, lots of examplesBased on the Java build tool, AntObsolete
  • Conventional Scripting ToolPowerShell – the Microsoft shell toolpsake – a PowerShell based build systemSupports scriptingCan automate many administrative tasks on Windows Server and most Microsoft server applicationsPart of Windows Fundamentals
  • Task LibrariesMSBuild Extension PackMSBuild Community TasksAutomate, Automate, AutomateAssembly InfoXML Peek & Poke, Transform ConfigCopy Files, Zip, PackageDocumentation
  • One Script, Builds EverythingCompletelyConsistentlyrunner.msbuildrunner.batVirtuous DisciplineRunner Runs Every Build StepAlways “Run the Runner”Avoid Integration HellPullRebuildCodeRebuildPush
  • Week 2Continuous Integration ServerSelect oneInstall itRun Build ScriptRebuild PhaseSoup-to-Nuts
  • No CI ServerDevelopers Push CodeFire and ForgetSCM RepositoryHolds Code RevisionsUnknown ConditionDanger ZoneDeferring the BuildIntegration HellLurking Quality Issues
  • Install CI ServerSCM TriggerRun runner.msbuild
  • CommercialMicrosoft’s Team Foundation Server
  • Free, Open SourceCruise Control .NET
  • Free, Open SourceJenkins
  • CommercialJetBrainsTeamCity
  • ObserveCode PushBuild SuccessReportBuild HistoryVisibilityBuild FeedbackImprove Personal ProcessStakeholder Visibility
  • Week 3Code AnalysisRun code analysis tool against the codebaseUnderstand the InspectionsFocus on the Minimum, RecommendedFind One Rule That’s Being ViolatedDecide that on one that’s worth fixingOne that’s worth monitoringFix Every Violation of That One InspectionBuild ScriptCode analysis running from within the build scriptRunning from within the CI serverBuild breaks if that one inspection rule is violated
  • No Code AnalysisDanger ZoneCritical Errors: these probably exist in the code, but you don’t know whereBad Practices: you could be following a bad coding practicesCode Smells: you could be following new and better coding practices
  • Identify an Analysis ToolStatic Code AnalysisRun the Analysis Tool within the CI Server
  • FxCop.NET Framework Guidelines
  • GendarmeFinds Common Problems
  • StyleCopHelps Enforce Coding Standards
  • NDependGo Deep: analysis in depth
  • SimianDuplicate Code Finder
  • Sonar 3DashboardRules, Alerts, Thresholds
  • Add to runner.msbuildRun PerformantAnalysisPer-Commit AnalysisCI ServerRun Performant AnalysisMonitorViolations Break the BuildNightly AnalysisRun Complete AnalysisAnalyzeEvaluate, TriageImproveUrgent, Important
  • Week 4Write One Automated Unit TestBuild ScriptHave the test run within the build scriptHave the test run within the CI serverCode AnalysisIdentify, fix and monitor 2 more inspections
  • No Automated TestsUnitIntegrationWhatDefines “Automated Testing”?Runs EverywhereEvery Developer’s MachineNo Manual …ConfigurationInterventionDeterministic, Isolated, Repeatable
  • Select a Testing FrameworkRun the Tests with a Scripting ToolRun the Tests within the CI Server
  • Testing FrameworkMSTest
  • Testing FrameworkMbUnit
  • Testing FrameworkxUnit.net
  • Testing FrameworkNUnit
  • Select a Mocking FrameworkAllows for Test IsolationEnables Interaction Testing
  • Mocking FrameworkRhinoMocks
  • Mocking FrameworkMoq
  • Add to runner.msbuildRun All Unit TestsPer-Commit TestingCI ServerRun All Unit TestsMonitorFailing Unit Test, Breaks the BuildNightly TestingRun Automated Integration Tests
  • Automated Unit TestingOne automated unit test assembly for each assembly/executable-under-testOne tests class for each class-under-testAchieve 100% class coverageMocking FrameworkUse a mocking frameworkCI ServerMake sure all unit tests runs on the CI serverCode AnalysisIdentify, fix and monitor 4 more code analysis violations.
  • Automated Unit TestingOne automated unit test assembly for each assembly/executable-under-testOne tests class for each class-under-testAchieve 100% class coverageMocking FrameworkUse a mocking frameworkCI ServerMake sure all unit tests runs on the CI serverCode AnalysisIdentify, fix and monitor 4 more code analysis violations.
  • Code ReviewDecide on the code review strategyPerform a “model code review”, together with everyone on the teamHash it out and define an approach that the team is willing to commit toAutomated Unit TestingWrite one unit test for each method in each class-under-testTry to achieve 100% method coverageCode AnalysisIdentify, fix and monitor 8 more code analysis violations
  • Code ReviewDecide on the code review strategyPerform a “model code review”, together with everyone on the teamHash it out and define an approach that the team is willing to commit toAutomated Unit TestingWrite one unit test for each method in each class-under-testTry to achieve 100% method coverageCode AnalysisIdentify, fix and monitor 8 more code analysis violations
  • PackagingDeploymentCode ReviewMake sure code reviews happenAutomated TestingWrite more unit testsTry to exceed 40% statement coverageCode AnalysisIdentify, fix and monitor 16 more code analysis violations
  • Automated DeploymentWrite a deployment/packaging scriptCode ReviewMake sure code reviews happenAutomated TestingWrite more unit testsTry to exceed 40% statement coverageCode AnalysisIdentify, fix and monitor 16 more code analysis violations
  • Automated DeploymentWrite a deployment/packaging scriptAutomated DeploymentAutomate the deployment to an integration environment as part of the “per commit” pipelineCode ReviewsPerform all code reviewsAutomated TestingWrite more unit testsTry to exceed 60% statement coverageCode AnalysisIdentify, fix and monitor 32 more code analysis violations
  • Automated DeploymentAutomate the deployment to TestAutomate the deployment to an integration environment as part of the “per commit” pipelineCode ReviewsPerform all code reviewsAutomated TestingWrite more unit testsTry to exceed 60% statement coverageCode AnalysisIdentify, fix and monitor 32 more code analysis violations
  • Automated TestingWrite more unit testsWrite more automated integration testsTry to exceed 80% statement coverage
  • Automated TestingWrite more unit testsTry to exceed 80% statement coverageCode ReviewsPerform all code reviewsAutomated DeploymentWorking with QA, automate the deployment to Test environment.Code AnalysisIdentify all applicable code analysis rulesFix and monitor all mandatory rules
  • RetrospectiveLiked: What did we do right?Learned: What did we learn?Lacked: What held us back?Longed for: What did we wish we had?Presentation to Project StakeholdersGather metrics along the wayGather success storiesDemonstrate the CI serverPresent the results

An Overview of .NET Best Practices An Overview of .NET Best Practices Presentation Transcript

  • An Overview of.NET Best Practices Stephen D. Ritchie 12 Nov 2012
  • Live Tweet, Tonight’s Slides and Examples• Twitter: @RuthlesssHelp @Apress• Slideshare: http://www.slideshare.net/ruthlesshelp• Github: http://github.com/ruthlesshelp Excella Consulting
  • Overall – Challenges Continuous Integration No CI Server No Code Analysis Not Triggered by SCM Excella Consulting -3-
  • Overall – Challenges Code Reviews Not Conducted Issues Not Tracked Issues Dropped Excella Consulting -4-
  • Current – Challenges Automated Builds and Deployments Manual Deployment No Automated Testing No Code Analysis Excella Consulting -5-
  • Current – Challenges Automated Unit Testing Low Code Coverage No Mocking Framework Failing or Ignored Tests Excella Consulting -6-
  • Opportunities Best Practices Matrix Complexity Value Risk Cost Excella Consulting -7-
  • Minimal, Essential Source Control Excella Consulting -8-
  • TFSExcella Consulting -9-
  • SVNExcella Consulting - 10 -
  • MercurialExcella Consulting - 11 -
  • GitExcella Consulting - 12 -
  • Level Metaphor Excella Consulting - 13 -
  • Go to Green 1 2 3 4 5 6 7 8 9 Excella Consulting - 14 -
  • Level 1 – Goals Build Script Excella Consulting - 15 -
  • Level 1 – Starting Point Manual Builds Excella Consulting - 16 -
  • MSBuildExcella Consulting - 17 -
  • NAntExcella Consulting - 18 -
  • PowerShellExcella Consulting - 19 -
  • ExtensionsExcella Consulting - 20 -
  • Level 1 – Example Example Build Script Excella Consulting - 21 -
  • Level 1 – ResultBuild ScriptOne Script,Builds Everything“Run the Runner” Excella Consulting - 22 -
  • Go to Green 1 2 3 4 5 6 7 8 9 Excella Consulting - 23 -
  • Level 2 – Goals Continuous Integration Excella Consulting - 24 -
  • Level 2 – Starting Point No CI Server Excella Consulting - 25 -
  • Level 2 – To Do Install CI Server Triggered by Code Push “Run the Runner” Excella Consulting - 26 -
  • TFSExcella Consulting - 27 -
  • CC.NETExcella Consulting - 28 -
  • JenkinsExcella Consulting - 29 -
  • TeamCityExcella Consulting - 30 -
  • Level 2 – Example CI Server Example Excella Consulting - 31 -
  • Level 2 – Result Observe & Report Excella Consulting - 32 -
  • Go to Green 1 2 3 4 5 6 7 8 9 Excella Consulting - 33 -
  • Level 3 – Goals Code Analysis Excella Consulting - 34 -
  • Level 3 – Starting Point No Code Analysis Excella Consulting - 35 -
  • Level 3 – To Do Analysis Tool Static Code Analysis Run with CI Server Excella Consulting - 36 -
  • FxCopExcella Consulting - 37 -
  • GendarmeExcella Consulting - 38 -
  • StyleCopExcella Consulting - 39 -
  • NDependExcella Consulting - 40 -
  • SimianExcella Consulting - 41 -
  • SonarExcella Consulting - 42 -
  • Level 3 – Example Analysis Tool Example FxCop 10 Excella Consulting - 43 -
  • Level 3 – Result Analyze, Improve, Monitor Excella Consulting - 44 -
  • Go to Green 1 2 3 4 5 6 7 8 9 Excella Consulting - 45 -
  • Level 4 – Goals Automate Testing Excella Consulting - 46 -
  • Level 4 – Starting Point No Tests Excella Consulting - 47 -
  • Level 4 – To Do Testing Framework Run with Runner Run with CI Server Excella Consulting - 48 -
  • MSTestExcella Consulting - 49 -
  • MBUnitExcella Consulting - 50 -
  • xUnit.netExcella Consulting - 51 -
  • NUnitExcella Consulting - 52 -
  • Level 4 – To Do Mocking Framework Isolation Interaction Testing Excella Consulting - 53 -
  • Rhino Mocks Excella Consulting - 54 -
  • MoqExcella Consulting - 55 -
  • Level 4 – Example Automate Testing Example Excella Consulting - 56 -
  • Level 4 – Results Passing Tests Excella Consulting - 57 -
  • Go to Green 1 2 3 4 5 6 7 8 9 Excella Consulting - 58 -
  • Level 5 – Goals Code Coverage + More Tests + More Code Analysis Excella Consulting - 59 -
  • Level 5 – To Do Coverage Tool Run in Visual Studio Run with CI Server Excella Consulting - 60 -
  • NCoverExcella Consulting - 61 -
  • OpenCoverExcella Consulting - 62 -
  • dotCoverExcella Consulting - 63 -
  • Level 5 – Example Code Coverage Example Excella Consulting - 64 -
  • Level 5 – Results 100% Class Coverage + More Code Analysis Excella Consulting - 65 -
  • Go to Green 1 2 3 4 5 6 7 8 9 Excella Consulting - 66 -
  • Level 6 – Goals Code Review + More Tests + More Code Analysis Excella Consulting - 67 -
  • Level 6 – To Do Pick Approach Share Opinions Track Issues Excella Consulting - 68 -
  • PairingExcella Consulting - 69 -
  • GroupExcella Consulting - 70 -
  • PeerExcella Consulting - 71 -
  • Level 6 – Example Code Review Example Peer Excella Consulting - 72 -
  • Level 6 – Results Reviewed Code 100% Method Coverage + More Code Analysis Excella Consulting - 73 -
  • Go to Green 1 2 3 4 5 6 7 8 9 Excella Consulting - 74 -
  • Level 7 – Goals Packaging + More Tests + More Coverage + More Code Analysis Excella Consulting - 75 -
  • MSIExcella Consulting - 76 -
  • Web Deploy Excella Consulting - 77 -
  • OctopusExcella Consulting - 78 -
  • Zip Archive Excella Consulting - 79 -
  • Level 7 – Example Packaging Example Zip Excella Consulting - 80 -
  • Level 7 – Results Packaged Deliverable Code Reviews 40% Line Coverage + More Code Analysis Excella Consulting - 81 -
  • Go to Green 1 2 3 4 5 6 7 8 9 Excella Consulting - 82 -
  • Level 8 – Goals Automated Deployments + More Tests + More Line Coverage + More Code Analysis Excella Consulting - 83 -
  • ScriptExcella Consulting - 84 -
  • Level 8 – Example Automated Deployment Example MSBuild Excella Consulting - 85 -
  • Level 8 – Results Automated Deployments + Code Reviews + 60% Line Coverage + More Code Analysis Excella Consulting - 86 -
  • Go to Green 1 2 3 4 5 6 7 8 9 Excella Consulting - 87 -
  • Level 9 – Goals Full Code Coverage + More Tests + More Coverage + More Code Analysis Excella Consulting - 88 -
  • TestingExcella Consulting - 89 -
  • Level 9 – Example Full Code Coverage Example Excella Consulting - 90 -
  • Level 9 – Results > 80% Line Coverage + Code Reviews Automated Deployments + More Code Analysis Excella Consulting - 91 -
  • Go to Green 1 2 3 4 5 6 7 8 9 Excella Consulting - 92 -
  • Overall – Results Continuous Integration CI Server Code Analysis Triggered by SCM Excella Consulting - 93 -
  • Overall – Results Code Reviews Conducted Regularly Issues Tracked Issues Resolved Excella Consulting - 94 -
  • Overall – Results Automated Builds and Deployments Automated Deployment Automated Testing Code Analysis Excella Consulting - 95 -
  • Overall – Results Automated Unit Testing Code Coverage: > 80% Mocking Framework Passing Tests: Priority Excella Consulting - 96 -
  • Follow On – Goals RetrospectivesPresentations Excella Consulting - 97 -
  • Further Discussion Any questions? Any comments? Excella Consulting
  • Shameless Self Promotion Time! 40% off eBook at apress.com Use promo code: PR0N3T Offer ends 15-Dec-2012 Excella Consulting
  • Contact Me• Twitter: @ruthlesshelp• Email: stephen.ritchie@excella.com• Blog: http://ruthlesslyhelpful.net• LinkedIn: http://www.linkedin.com/in/sritchie Excella Consulting
  • Slides and Examples• Slideshare: http://www.slideshare.net/ruthlesshelp• Github: http://github.com/ruthlesshelp Excella Consulting