An Overview of .NET Best Practices

Post on 26-May-2015

562 views 5 download

Tags:

description

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.

Transcript of An Overview of .NET Best Practices

An Overview of.NET Best Practices

Stephen D. Ritchie

15 Nov 2012

Excella Consulting

Live Tweet, Tonight’s Slides and Examples

• Twitter: @RuthlessHelp@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

- 3 -

Excella Consulting

Overall – Challenges

Code Reviews

Not Conducted

Issues Not Tracked

Issues Dropped

- 4 -

Excella Consulting

Current – Challenges

Automated Builds and Deployments

Manual Deployment

No Automated Testing

No Code Analysis

- 5 -

Excella Consulting

Current – Challenges

Automated Unit Testing

Low Code Coverage

No Mocking Framework

Failing or Ignored Tests

- 6 -

Excella Consulting

Opportunities

- 7 -

Best Practices MatrixComplexity

Risk

Cost

Value

Excella Consulting

Minimal, Essential

Source Control

- 8 -

Excella Consulting

TFS

- 9 -

Excella Consulting

SVN

- 10 -

Excella Consulting

Mercurial

- 11 -

Excella Consulting

Git

- 12 -

Excella Consulting

Level Metaphor

- 13 -

Excella Consulting

32

4 5 6

7 8 9

1

Go to Green

- 14 -

Excella Consulting

Level 1 – Goals

Build Script

- 15 -

Excella Consulting

Level 1 – Starting Point

Manual Builds

- 16 -

Excella Consulting

MSBuild

- 17 -

Excella Consulting

NAnt

- 18 -

Excella Consulting

PowerShell

- 19 -

Excella Consulting

Extensions

- 20 -

Excella Consulting

Level 1 – Example

- 21 -

Example Build Script

Excella Consulting

Level 1 – Result

One Script, Builds Everything

- 22 -

“Run the Runner”

Build Script

Excella Consulting

32

4 5 6

7 8 9

1

Go to Green

- 23 -

Excella Consulting

Level 2 – Goals

Continuous Integration

- 24 -

Excella Consulting

Level 2 – Starting Point

No CI Server

- 25 -

Excella Consulting

Level 2 – To Do

Install CI Server

Triggered by Code Push

“Run the Runner”

- 26 -

Excella Consulting

TFS

- 27 -

Excella Consulting

CC.NET

- 28 -

Excella Consulting

Jenkins

- 29 -

Excella Consulting

TeamCity

- 30 -

Excella Consulting

Level 2 – Example

- 31 -

CI Server Example

Excella Consulting

Level 2 – Result

Observe & Report

- 32 -

Excella Consulting

3

4 5 6

7 8 9

1 2

Go to Green

- 33 -

Excella Consulting

Level 3 – Goals

Code Analysis

- 34 -

Excella Consulting

Level 3 – Starting Point

No Code Analysis

- 35 -

Excella Consulting

Level 3 – To Do

Analysis Tool

Static Code Analysis

Run with CI Server

- 36 -

Excella Consulting

FxCop

- 37 -

Excella Consulting

Gendarme

- 38 -

Excella Consulting

StyleCop

- 39 -

Excella Consulting

NDepend

- 40 -

Excella Consulting

Simian

- 41 -

Excella Consulting

Sonar

- 42 -

Excella Consulting

Level 3 – Example

FxCop 10

- 43 -

Analysis Tool Example

Excella Consulting

Level 3 – Result

Analyze, Improve, Monitor

- 44 -

Excella Consulting

4 5 6

7 8 9

1 2 3

Go to Green

- 45 -

Excella Consulting

Level 4 – Goals

Automate Testing

- 46 -

Excella Consulting

Level 4 – Starting Point

No Tests

- 47 -

Excella Consulting

Level 4 – To Do

Testing Framework

Run with Runner

Run with CI Server

- 48 -

Excella Consulting

MSTest

- 49 -

Excella Consulting

MBUnit

- 50 -

Excella Consulting

xUnit.net

- 51 -

Excella Consulting

NUnit

- 52 -

Excella Consulting

Level 4 – To Do

Mocking Framework

Isolation

Interaction Testing

- 53 -

Excella Consulting

Rhino Mocks

- 54 -

Excella Consulting

Moq

- 55 -

Excella Consulting

Level 4 – Example

- 56 -

Automate Testing Example

Excella Consulting

Level 4 – Results

Passing Tests

- 57 -

Excella Consulting

5 6

7 8 9

1 2 3

4

Go to Green

- 58 -

Excella Consulting

Level 5 – Goals

Code Coverage

+ More Tests

+ More Code Analysis

- 59 -

Excella Consulting

Level 5 – To Do

Coverage Tool

Run in Visual Studio

Run with CI Server

- 60 -

Excella Consulting

NCover

- 61 -

Excella Consulting

OpenCover

- 62 -

Excella Consulting

dotCover

- 63 -

Excella Consulting

Level 5 – Example

- 64 -

Code Coverage Example

Excella Consulting

Level 5 – Results

100% Class Coverage

+ More Code Analysis

- 65 -

Excella Consulting

6

7 8 9

1 2 3

4 5

Go to Green

- 66 -

Excella Consulting

Level 6 – Goals

Code Review

+ More Tests

+ More Code Analysis

- 67 -

Excella Consulting

Level 6 – To Do

Pick Approach

Share Opinions

Track Issues

- 68 -

Excella Consulting

Pairing

- 69 -

Excella Consulting

Group

- 70 -

Excella Consulting

Peer

- 71 -

Excella Consulting

Level 6 – Example

Peer

- 72 -

Code Review Example

Excella Consulting

Level 6 – Results

Reviewed Code

100% Method Coverage

+ More Code Analysis

- 73 -

Excella Consulting

7 8 9

1 2 3

4 5 6

Go to Green

- 74 -

Excella Consulting

Level 7 – Goals

Packaging

+ More Coverage

+ More Code Analysis

+ More Tests

- 75 -

Excella Consulting

MSI

- 76 -

Excella Consulting

Web Deploy

- 77 -

Excella Consulting

Octopus

- 78 -

Excella Consulting

Zip Archive

- 79 -

Excella Consulting

Level 7 – Example

Zip

- 80 -

Packaging Example

Excella Consulting

Level 7 – Results

Packaged Deliverable

Code Reviews

40% Line Coverage

+ More Code Analysis

- 81 -

Excella Consulting

8 9

1 2 3

4 5 6

7

Go to Green

- 82 -

Excella Consulting

Level 8 – Goals

Automated Deployments

+ More Tests

+ More Line Coverage+ More Code Analysis

- 83 -

Excella Consulting

Script

- 84 -

Excella Consulting

Level 8 – Example

MSBuild

- 85 -

Automated Deployment Example

Excella Consulting

Level 8 – Results

Automated Deployments

+ Code Reviews

+ 60% Line Coverage

+ More Code Analysis

- 86 -

Excella Consulting

9

1 2 3

4 5 6

7 8

Go to Green

- 87 -

Excella Consulting

Level 9 – Goals

Full Code Coverage

+ More Tests

+ More Coverage+ More Code Analysis

- 88 -

Excella Consulting

Testing

- 89 -

Excella Consulting

Level 9 – Example

- 90 -

Full Code Coverage Example

Excella Consulting

Level 9 – Results

> 80% Line Coverage

+ Code Reviews

Automated Deployments

+ More Code Analysis

- 91 -

Excella Consulting

1 2 3

4 5 6

7 8 9

Go to Green

- 92 -

Excella Consulting

Overall – Results

Continuous Integration

CI Server

Code Analysis

Triggered by SCM

- 93 -

Excella Consulting

Overall – Results

Code Reviews

Conducted Regularly

Issues Tracked

Issues Resolved

- 94 -

Excella Consulting

Overall – Results

Automated Builds and Deployments

Automated Deployment

Automated Testing

Code Analysis

- 95 -

Excella Consulting

Overall – Results

Automated Unit Testing

Code Coverage: > 80%

Mocking Framework

Passing Tests: Priority

- 96 -

Excella Consulting

Follow On – Goals

Retrospectives

Presentations

- 97 -

Excella Consulting

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