an overview of .net best practices

101
An Overview of .NET Best Practices Stephen D. Ritchie 12 Nov 2012

Upload: stephen-ritchie

Post on 28-May-2015

386 views

Category:

Technology


0 download

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

Page 1: An Overview of .NET Best Practices

An Overview of.NET Best Practices

Stephen D. Ritchie

12 Nov 2012

Page 2: An Overview of .NET Best Practices

Excella Consulting

Live Tweet, Tonight’s Slides and Examples

• Twitter: @RuthlesssHelp@Apress

• Slideshare: http://www.slideshare.net/ruthlesshelp

• Github: http://github.com/ruthlesshelp

Page 3: An Overview of .NET Best Practices

Excella Consulting

Overall – Challenges

Continuous Integration

No CI Server

No Code Analysis

Not Triggered by SCM

- 3 -

Page 4: An Overview of .NET Best Practices

Excella Consulting

Overall – Challenges

Code Reviews

Not Conducted

Issues Not Tracked

Issues Dropped

- 4 -

Page 5: An Overview of .NET Best Practices

Excella Consulting

Current – Challenges

Automated Builds and Deployments

Manual Deployment

No Automated Testing

No Code Analysis

- 5 -

Page 6: An Overview of .NET Best Practices

Excella Consulting

Current – Challenges

Automated Unit Testing

Low Code Coverage

No Mocking Framework

Failing or Ignored Tests

- 6 -

Page 7: An Overview of .NET Best Practices

Excella Consulting

Opportunities

- 7 -

Best Practices MatrixComplexity

Risk

Cost

Value

Page 8: An Overview of .NET Best Practices

Excella Consulting

Minimal, Essential

Source Control

- 8 -

Page 9: An Overview of .NET Best Practices

Excella Consulting

TFS

- 9 -

Page 10: An Overview of .NET Best Practices

Excella Consulting

SVN

- 10 -

Page 11: An Overview of .NET Best Practices

Excella Consulting

Mercurial

- 11 -

Page 12: An Overview of .NET Best Practices

Excella Consulting

Git

- 12 -

Page 13: An Overview of .NET Best Practices

Excella Consulting

Level Metaphor

- 13 -

Page 14: An Overview of .NET Best Practices

Excella Consulting

32

4 5 6

7 8 9

1

Go to Green

- 14 -

Page 15: An Overview of .NET Best Practices

Excella Consulting

Level 1 – Goals

Build Script

- 15 -

Page 16: An Overview of .NET Best Practices

Excella Consulting

Level 1 – Starting Point

Manual Builds

- 16 -

Page 17: An Overview of .NET Best Practices

Excella Consulting

MSBuild

- 17 -

Page 18: An Overview of .NET Best Practices

Excella Consulting

NAnt

- 18 -

Page 19: An Overview of .NET Best Practices

Excella Consulting

PowerShell

- 19 -

Page 20: An Overview of .NET Best Practices

Excella Consulting

Extensions

- 20 -

Page 21: An Overview of .NET Best Practices

Excella Consulting

Level 1 – Example

- 21 -

Example Build Script

Page 22: An Overview of .NET Best Practices

Excella Consulting

Level 1 – Result

One Script, Builds Everything

- 22 -

“Run the Runner”

Build Script

Page 23: An Overview of .NET Best Practices

Excella Consulting

32

4 5 6

7 8 9

1

Go to Green

- 23 -

Page 24: An Overview of .NET Best Practices

Excella Consulting

Level 2 – Goals

Continuous Integration

- 24 -

Page 25: An Overview of .NET Best Practices

Excella Consulting

Level 2 – Starting Point

No CI Server

- 25 -

Page 26: An Overview of .NET Best Practices

Excella Consulting

Level 2 – To Do

Install CI Server

Triggered by Code Push

“Run the Runner”

- 26 -

Page 27: An Overview of .NET Best Practices

Excella Consulting

TFS

- 27 -

Page 28: An Overview of .NET Best Practices

Excella Consulting

CC.NET

- 28 -

Page 29: An Overview of .NET Best Practices

Excella Consulting

Jenkins

- 29 -

Page 30: An Overview of .NET Best Practices

Excella Consulting

TeamCity

- 30 -

Page 31: An Overview of .NET Best Practices

Excella Consulting

Level 2 – Example

- 31 -

CI Server Example

Page 32: An Overview of .NET Best Practices

Excella Consulting

Level 2 – Result

Observe & Report

- 32 -

Page 33: An Overview of .NET Best Practices

Excella Consulting

3

4 5 6

7 8 9

1 2

Go to Green

- 33 -

Page 34: An Overview of .NET Best Practices

Excella Consulting

Level 3 – Goals

Code Analysis

- 34 -

Page 35: An Overview of .NET Best Practices

Excella Consulting

Level 3 – Starting Point

No Code Analysis

- 35 -

Page 36: An Overview of .NET Best Practices

Excella Consulting

Level 3 – To Do

Analysis Tool

Static Code Analysis

Run with CI Server

- 36 -

Page 37: An Overview of .NET Best Practices

Excella Consulting

FxCop

- 37 -

Page 38: An Overview of .NET Best Practices

Excella Consulting

Gendarme

- 38 -

Page 39: An Overview of .NET Best Practices

Excella Consulting

StyleCop

- 39 -

Page 40: An Overview of .NET Best Practices

Excella Consulting

NDepend

- 40 -

Page 41: An Overview of .NET Best Practices

Excella Consulting

Simian

- 41 -

Page 42: An Overview of .NET Best Practices

Excella Consulting

Sonar

- 42 -

Page 43: An Overview of .NET Best Practices

Excella Consulting

Level 3 – Example

FxCop 10

- 43 -

Analysis Tool Example

Page 44: An Overview of .NET Best Practices

Excella Consulting

Level 3 – Result

Analyze, Improve, Monitor

- 44 -

Page 45: An Overview of .NET Best Practices

Excella Consulting

4 5 6

7 8 9

1 2 3

Go to Green

- 45 -

Page 46: An Overview of .NET Best Practices

Excella Consulting

Level 4 – Goals

Automate Testing

- 46 -

Page 47: An Overview of .NET Best Practices

Excella Consulting

Level 4 – Starting Point

No Tests

- 47 -

Page 48: An Overview of .NET Best Practices

Excella Consulting

Level 4 – To Do

Testing Framework

Run with Runner

Run with CI Server

- 48 -

Page 49: An Overview of .NET Best Practices

Excella Consulting

MSTest

- 49 -

Page 50: An Overview of .NET Best Practices

Excella Consulting

MBUnit

- 50 -

Page 51: An Overview of .NET Best Practices

Excella Consulting

xUnit.net

- 51 -

Page 52: An Overview of .NET Best Practices

Excella Consulting

NUnit

- 52 -

Page 53: An Overview of .NET Best Practices

Excella Consulting

Level 4 – To Do

Mocking Framework

Isolation

Interaction Testing

- 53 -

Page 54: An Overview of .NET Best Practices

Excella Consulting

Rhino Mocks

- 54 -

Page 55: An Overview of .NET Best Practices

Excella Consulting

Moq

- 55 -

Page 56: An Overview of .NET Best Practices

Excella Consulting

Level 4 – Example

- 56 -

Automate Testing Example

Page 57: An Overview of .NET Best Practices

Excella Consulting

Level 4 – Results

Passing Tests

- 57 -

Page 58: An Overview of .NET Best Practices

Excella Consulting

5 6

7 8 9

1 2 3

4

Go to Green

- 58 -

Page 59: An Overview of .NET Best Practices

Excella Consulting

Level 5 – Goals

Code Coverage

+ More Tests

+ More Code Analysis

- 59 -

Page 60: An Overview of .NET Best Practices

Excella Consulting

Level 5 – To Do

Coverage Tool

Run in Visual Studio

Run with CI Server

- 60 -

Page 61: An Overview of .NET Best Practices

Excella Consulting

NCover

- 61 -

Page 62: An Overview of .NET Best Practices

Excella Consulting

OpenCover

- 62 -

Page 63: An Overview of .NET Best Practices

Excella Consulting

dotCover

- 63 -

Page 64: An Overview of .NET Best Practices

Excella Consulting

Level 5 – Example

- 64 -

Code Coverage Example

Page 65: An Overview of .NET Best Practices

Excella Consulting

Level 5 – Results

100% Class Coverage

+ More Code Analysis

- 65 -

Page 66: An Overview of .NET Best Practices

Excella Consulting

6

7 8 9

1 2 3

4 5

Go to Green

- 66 -

Page 67: An Overview of .NET Best Practices

Excella Consulting

Level 6 – Goals

Code Review

+ More Tests

+ More Code Analysis

- 67 -

Page 68: An Overview of .NET Best Practices

Excella Consulting

Level 6 – To Do

Pick Approach

Share Opinions

Track Issues

- 68 -

Page 69: An Overview of .NET Best Practices

Excella Consulting

Pairing

- 69 -

Page 70: An Overview of .NET Best Practices

Excella Consulting

Group

- 70 -

Page 71: An Overview of .NET Best Practices

Excella Consulting

Peer

- 71 -

Page 72: An Overview of .NET Best Practices

Excella Consulting

Level 6 – Example

Peer

- 72 -

Code Review Example

Page 73: An Overview of .NET Best Practices

Excella Consulting

Level 6 – Results

Reviewed Code

100% Method Coverage

+ More Code Analysis

- 73 -

Page 74: An Overview of .NET Best Practices

Excella Consulting

7 8 9

1 2 3

4 5 6

Go to Green

- 74 -

Page 75: An Overview of .NET Best Practices

Excella Consulting

Level 7 – Goals

Packaging

+ More Coverage

+ More Code Analysis

+ More Tests

- 75 -

Page 76: An Overview of .NET Best Practices

Excella Consulting

MSI

- 76 -

Page 77: An Overview of .NET Best Practices

Excella Consulting

Web Deploy

- 77 -

Page 78: An Overview of .NET Best Practices

Excella Consulting

Octopus

- 78 -

Page 79: An Overview of .NET Best Practices

Excella Consulting

Zip Archive

- 79 -

Page 80: An Overview of .NET Best Practices

Excella Consulting

Level 7 – Example

Zip

- 80 -

Packaging Example

Page 81: An Overview of .NET Best Practices

Excella Consulting

Level 7 – Results

Packaged Deliverable

Code Reviews

40% Line Coverage

+ More Code Analysis

- 81 -

Page 82: An Overview of .NET Best Practices

Excella Consulting

8 9

1 2 3

4 5 6

7

Go to Green

- 82 -

Page 83: An Overview of .NET Best Practices

Excella Consulting

Level 8 – Goals

Automated Deployments

+ More Tests

+ More Line Coverage+ More Code Analysis

- 83 -

Page 84: An Overview of .NET Best Practices

Excella Consulting

Script

- 84 -

Page 85: An Overview of .NET Best Practices

Excella Consulting

Level 8 – Example

MSBuild

- 85 -

Automated Deployment Example

Page 86: An Overview of .NET Best Practices

Excella Consulting

Level 8 – Results

Automated Deployments

+ Code Reviews

+ 60% Line Coverage

+ More Code Analysis

- 86 -

Page 87: An Overview of .NET Best Practices

Excella Consulting

9

1 2 3

4 5 6

7 8

Go to Green

- 87 -

Page 88: An Overview of .NET Best Practices

Excella Consulting

Level 9 – Goals

Full Code Coverage

+ More Tests

+ More Coverage+ More Code Analysis

- 88 -

Page 89: An Overview of .NET Best Practices

Excella Consulting

Testing

- 89 -

Page 90: An Overview of .NET Best Practices

Excella Consulting

Level 9 – Example

- 90 -

Full Code Coverage Example

Page 91: An Overview of .NET Best Practices

Excella Consulting

Level 9 – Results

> 80% Line Coverage

+ Code Reviews

Automated Deployments

+ More Code Analysis

- 91 -

Page 92: An Overview of .NET Best Practices

Excella Consulting

1 2 3

4 5 6

7 8 9

Go to Green

- 92 -

Page 93: An Overview of .NET Best Practices

Excella Consulting

Overall – Results

Continuous Integration

CI Server

Code Analysis

Triggered by SCM

- 93 -

Page 94: An Overview of .NET Best Practices

Excella Consulting

Overall – Results

Code Reviews

Conducted Regularly

Issues Tracked

Issues Resolved

- 94 -

Page 95: An Overview of .NET Best Practices

Excella Consulting

Overall – Results

Automated Builds and Deployments

Automated Deployment

Automated Testing

Code Analysis

- 95 -

Page 96: An Overview of .NET Best Practices

Excella Consulting

Overall – Results

Automated Unit Testing

Code Coverage: > 80%

Mocking Framework

Passing Tests: Priority

- 96 -

Page 97: An Overview of .NET Best Practices

Excella Consulting

Follow On – Goals

Retrospectives

Presentations

- 97 -

Page 98: An Overview of .NET Best Practices

Excella Consulting

Further Discussion

Any questions?

Any comments?

Page 99: An Overview of .NET Best Practices

Excella Consulting

Shameless Self Promotion Time!

40% off eBook at apress.com

Use promo code:PR0N3T

Offer ends 15-Dec-2012

Page 100: An Overview of .NET Best Practices

Excella Consulting

Contact Me

• Twitter: @ruthlesshelp

• Email: [email protected]

• Blog: http://ruthlesslyhelpful.net

• LinkedIn: http://www.linkedin.com/in/sritchie

Page 101: An Overview of .NET Best Practices

Excella Consulting

Slides and Examples

• Slideshare: http://www.slideshare.net/ruthlesshelp

• Github: http://github.com/ruthlesshelp