Overview of .NET Best Practices

96
An Overview of .NET Best Practices Stephen D. Ritchie Rappahannock Area Developers .NET Users Group 17 Mar 2015

Transcript of Overview of .NET Best Practices

Page 1: Overview of .NET Best Practices

An Overview of

.NET Best Practices

Stephen D. Ritchie

Rappahannock Area Developers .NET Users Group

17 Mar 2015

Page 2: Overview of .NET Best Practices

Excella Consulting

Overall – Challenges

Continuous Integration

No CI Server

No Code Analysis

Not Triggered by SCM

- 2 -

Page 3: Overview of .NET Best Practices

Excella Consulting

Overall – Challenges

Code Reviews

Not Conducted

Issues Not Tracked

Issues Dropped

- 3 -

Page 4: Overview of .NET Best Practices

Excella Consulting

Current – Challenges

Automated Builds and

Deployments

Manual Deployment

No Automated Testing

No Code Analysis

- 4 -

Page 5: Overview of .NET Best Practices

Excella Consulting

Current – Challenges

Automated Unit Testing

Low Code Coverage

No Mocking Framework

Failing or Ignored Tests

- 5 -

Page 6: Overview of .NET Best Practices

Excella Consulting

Opportunities

- 6 -

Best Practices Matrix

Complexity

Risk

Cost

Value

Page 7: Overview of .NET Best Practices

Excella Consulting

Minimal, Essential

Source Control

- 7 -

Page 8: Overview of .NET Best Practices

Excella Consulting

TFS

- 8 -

Page 9: Overview of .NET Best Practices

Excella Consulting

SVN

- 9 -

Page 10: Overview of .NET Best Practices

Excella Consulting

Mercurial

- 10 -

Page 11: Overview of .NET Best Practices

Excella Consulting

Git

- 11 -

Page 12: Overview of .NET Best Practices

Excella Consulting

Level Metaphor

- 12 -

Page 13: Overview of .NET Best Practices

Excella Consulting

32

4 5 6

7 8 9

1

Go to Green

- 13 -

Page 14: Overview of .NET Best Practices

Excella Consulting

Level 1 – Goals

Build Script

- 14 -

Page 15: Overview of .NET Best Practices

Excella Consulting

Level 1 – Starting Point

Manual Builds

- 15 -

Page 16: Overview of .NET Best Practices

Excella Consulting

MSBuild

- 16 -

Page 17: Overview of .NET Best Practices

Excella Consulting

NAnt

- 17 -

Page 18: Overview of .NET Best Practices

Excella Consulting

PowerShell

- 18 -

Page 19: Overview of .NET Best Practices

Excella Consulting

Extensions

- 19 -

Page 20: Overview of .NET Best Practices

Excella Consulting

Level 1 – Example

- 20 -

Example Build

Script

Page 21: Overview of .NET Best Practices

Excella Consulting

Level 1 – Result

One Script,

Builds Everything

- 21 -

“Run the Runner”

Build Script

Page 22: Overview of .NET Best Practices

Excella Consulting

32

4 5 6

7 8 9

1

Go to Green

- 22 -

Page 23: Overview of .NET Best Practices

Excella Consulting

Level 2 – Goals

Continuous

Integration

- 23 -

Page 24: Overview of .NET Best Practices

Excella Consulting

Level 2 – Starting Point

No CI Server

- 24 -

Page 25: Overview of .NET Best Practices

Excella Consulting

Level 2 – To Do

Install CI Server

Triggered by Code Push

“Run the Runner”

- 25 -

Page 26: Overview of .NET Best Practices

Excella Consulting

TFS

- 26 -

Page 27: Overview of .NET Best Practices

Excella Consulting

CC.NET

- 27 -

Page 28: Overview of .NET Best Practices

Excella Consulting

Jenkins

- 28 -

Page 29: Overview of .NET Best Practices

Excella Consulting

TeamCity

- 29 -

Page 30: Overview of .NET Best Practices

Excella Consulting

Level 2 – Example

- 30 -

CI Server

Example

Page 31: Overview of .NET Best Practices

Excella Consulting

Level 2 – Result

Observe & Report

- 31 -

Page 32: Overview of .NET Best Practices

Excella Consulting

3

4 5 6

7 8 9

1 2

Go to Green

- 32 -

Page 33: Overview of .NET Best Practices

Excella Consulting

Level 3 – Goals

Code Analysis

- 33 -

Page 34: Overview of .NET Best Practices

Excella Consulting

Level 3 – Starting Point

No Code Analysis

- 34 -

Page 35: Overview of .NET Best Practices

Excella Consulting

Level 3 – To Do

Analysis Tool

Static Code Analysis

Run with CI Server

- 35 -

Page 36: Overview of .NET Best Practices

Excella Consulting

FxCop

- 36 -

Page 37: Overview of .NET Best Practices

Excella Consulting

Gendarme

- 37 -

Page 38: Overview of .NET Best Practices

Excella Consulting

StyleCop

- 38 -

Page 39: Overview of .NET Best Practices

Excella Consulting

NDepend

- 39 -

Page 40: Overview of .NET Best Practices

Excella Consulting

Simian

- 40 -

Page 41: Overview of .NET Best Practices

Excella Consulting

Sonar

- 41 -

Page 42: Overview of .NET Best Practices

Excella Consulting

Level 3 – Example

FxCop 10

- 42 -

Analysis Tool

Example

Page 43: Overview of .NET Best Practices

Excella Consulting

Level 3 – Result

Analyze,

Improve,

Monitor

- 43 -

Page 44: Overview of .NET Best Practices

Excella Consulting

4 5 6

7 8 9

1 2 3

Go to Green

- 44 -

Page 45: Overview of .NET Best Practices

Excella Consulting

Level 4 – Goals

Automate Testing

- 45 -

Page 46: Overview of .NET Best Practices

Excella Consulting

Level 4 – Starting Point

No Tests

- 46 -

Page 47: Overview of .NET Best Practices

Excella Consulting

Level 4 – To Do

Testing Framework

Run with Runner

Run with CI Server

- 47 -

Page 48: Overview of .NET Best Practices

Excella Consulting

MSTest

- 48 -

Page 49: Overview of .NET Best Practices

Excella Consulting

MBUnit

- 49 -

Page 50: Overview of .NET Best Practices

Excella Consulting

xUnit.net

- 50 -

Page 51: Overview of .NET Best Practices

Excella Consulting

NUnit

- 51 -

Page 52: Overview of .NET Best Practices

Excella Consulting

Level 4 – To Do

Mocking Framework

Isolation

Interaction Testing

- 52 -

Page 53: Overview of .NET Best Practices

Excella Consulting

Rhino Mocks

- 53 -

Page 54: Overview of .NET Best Practices

Excella Consulting

Moq

- 54 -

Page 55: Overview of .NET Best Practices

Excella Consulting

Level 4 – Example

- 55 -

Automate Testing

Example

Page 56: Overview of .NET Best Practices

Excella Consulting

Level 4 – Results

Passing

Tests

- 56 -

Page 57: Overview of .NET Best Practices

Excella Consulting

5 6

7 8 9

1 2 3

4

Go to Green

- 57 -

Page 58: Overview of .NET Best Practices

Excella Consulting

Level 5 – Goals

Code Coverage

+ More Tests

+ More Code Analysis

- 58 -

Page 59: Overview of .NET Best Practices

Excella Consulting

Level 5 – To Do

Coverage Tool

Run in Visual Studio

Run with CI Server

- 59 -

Page 60: Overview of .NET Best Practices

Excella Consulting

NCover

- 60 -

Page 61: Overview of .NET Best Practices

Excella Consulting

OpenCover

- 61 -

Page 62: Overview of .NET Best Practices

Excella Consulting

dotCover

- 62 -

Page 63: Overview of .NET Best Practices

Excella Consulting

Level 5 – Example

- 63 -

Code Coverage

Example

Page 64: Overview of .NET Best Practices

Excella Consulting

Level 5 – Results

100% Class Coverage

+ More Code Analysis

- 64 -

Page 65: Overview of .NET Best Practices

Excella Consulting

6

7 8 9

1 2 3

4 5

Go to Green

- 65 -

Page 66: Overview of .NET Best Practices

Excella Consulting

Level 6 – Goals

Code Review

+ More Tests

+ More Code Analysis

- 66 -

Page 67: Overview of .NET Best Practices

Excella Consulting

Level 6 – To Do

Pick Approach

Share Opinions

Track Issues

- 67 -

Page 68: Overview of .NET Best Practices

Excella Consulting

Pairing

- 68 -

Page 69: Overview of .NET Best Practices

Excella Consulting

Group

- 69 -

Page 70: Overview of .NET Best Practices

Excella Consulting

Peer

- 70 -

Page 71: Overview of .NET Best Practices

Excella Consulting

Level 6 – Example

Peer

- 71 -

Code Review

Example

Page 72: Overview of .NET Best Practices

Excella Consulting

Level 6 – Results

Reviewed Code

100% Method Coverage

+ More Code Analysis

- 72 -

Page 73: Overview of .NET Best Practices

Excella Consulting

7 8 9

1 2 3

4 5 6

Go to Green

- 73 -

Page 74: Overview of .NET Best Practices

Excella Consulting

Level 7 – Goals

Packaging

+ More Coverage

+ More Code Analysis

+ More Tests

- 74 -

Page 75: Overview of .NET Best Practices

Excella Consulting

MSI

- 75 -

Page 76: Overview of .NET Best Practices

Excella Consulting

Web Deploy

- 76 -

Page 77: Overview of .NET Best Practices

Excella Consulting

Octopus

- 77 -

Page 78: Overview of .NET Best Practices

Excella Consulting

Zip Archive

- 78 -

Page 79: Overview of .NET Best Practices

Excella Consulting

Level 7 – Example

Zip

- 79 -

Packaging Example

Page 80: Overview of .NET Best Practices

Excella Consulting

Level 7 – Results

Packaged Deliverable

Code Reviews

40% Line Coverage

+ More Code Analysis

- 80 -

Page 81: Overview of .NET Best Practices

Excella Consulting

8 9

1 2 3

4 5 6

7

Go to Green

- 81 -

Page 82: Overview of .NET Best Practices

Excella Consulting

Level 8 – Goals

Automated

Deployments

+ More Tests

+ More Line Coverage

+ More Code Analysis

- 82 -

Page 83: Overview of .NET Best Practices

Excella Consulting

Script

- 83 -

Page 84: Overview of .NET Best Practices

Excella Consulting

Level 8 – Example

MSBuild

- 84 -

Automated

Deployment Example

Page 85: Overview of .NET Best Practices

Excella Consulting

Level 8 – Results

Automated

Deployments

+ Code Reviews

+ 60% Line Coverage

+ More Code Analysis

- 85 -

Page 86: Overview of .NET Best Practices

Excella Consulting

9

1 2 3

4 5 6

7 8

Go to Green

- 86 -

Page 87: Overview of .NET Best Practices

Excella Consulting

Level 9 – Goals

Full Code Coverage

+ More Tests

+ More Coverage

+ More Code Analysis

- 87 -

Page 88: Overview of .NET Best Practices

Excella Consulting

Testing

- 88 -

Page 89: Overview of .NET Best Practices

Excella Consulting

Level 9 – Example

- 89 -

Full Code Coverage

Example

Page 90: Overview of .NET Best Practices

Excella Consulting

Level 9 – Results

> 80% Line Coverage

+ Code Reviews

Automated Deployments

+ More Code Analysis

- 90 -

Page 91: Overview of .NET Best Practices

Excella Consulting

1 2 3

4 5 6

7 8 9

Go to Green

- 91 -

Page 92: Overview of .NET Best Practices

Excella Consulting

Overall – Results

Continuous Integration

CI Server

Code Analysis

Triggered by SCM

- 92 -

Page 93: Overview of .NET Best Practices

Excella Consulting

Overall – Results

Code Reviews

Conducted Regularly

Issues Tracked

Issues Resolved

- 93 -

Page 94: Overview of .NET Best Practices

Excella Consulting

Overall – Results

Automated Builds and

Deployments

Automated Deployment

Automated Testing

Code Analysis

- 94 -

Page 95: Overview of .NET Best Practices

Excella Consulting

Overall – Results

Automated Unit Testing

Code Coverage: > 80%

Mocking Framework

Passing Tests: Priority

- 95 -

Page 96: Overview of .NET Best Practices

Excella Consulting

Follow On – Goals

Retrospectives

Presentations

- 96 -