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.
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
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
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