building robust and reliable software jason anderson, microsoft [email protected]

46
Building Robust and Reliable Software Jason Anderson, Microsoft [email protected]

Upload: garey-robertson

Post on 31-Dec-2015

233 views

Category:

Documents


4 download

TRANSCRIPT

Page 1: Building Robust and Reliable Software Jason Anderson, Microsoft jasand@microsoft.com

Building Robust and Reliable SoftwareJason Anderson, Microsoft

[email protected]

Page 2: Building Robust and Reliable Software Jason Anderson, Microsoft jasand@microsoft.com

Agenda

• Team System Overview• Static Analysis• Profiling• Unit Testing• Test Driven Development• Code Coverage• Team Developer and Team Foundation

Server• Questions

Page 3: Building Robust and Reliable Software Jason Anderson, Microsoft jasand@microsoft.com

Development Teams

InfrastructureInfrastructureArchitectArchitect

SolutionSolutionArchitectArchitect

Project ManagerProject Manager

DeveloperDeveloper

TesterTester

End UserEnd User

Page 4: Building Robust and Reliable Software Jason Anderson, Microsoft jasand@microsoft.com

Visual Studio Team SystemPro

cess

an

d A

rch

itect

ure

Pro

cess

an

d A

rch

itect

ure

G

uid

an

ceG

uid

an

ce

Vis

ual S

tud

io In

du

stry

V

isu

al S

tud

io In

du

stry

Part

ners

Part

ners

Dynamic Code Analyzer

Visual Studio

Team Architect

Static Code Analyzer

Code Profiler

Unit Testing

Code Coverage

Visio and UML Modeling

Team Foundation Client (includes CAL)

Visual Studio Professional Edition

Class Designer

Load Testing

Manual Testing

Test Case Management

Application Designer

Logical Infra. Designer

Deployment Designer

Visual Studio

Team DeveloperVisual Studio

Team TestDynamic Code Analyzer

Static Code Analyzer

Code Profiler

Unit Testing

Code Coverage

Change Management

Work Item Tracking

Reporting

Project Site

Visual Studio

Team Foundation Integration Services

Project ManagementBig Build

Page 5: Building Robust and Reliable Software Jason Anderson, Microsoft jasand@microsoft.com

Static AnalysisStatic Analysis

Page 6: Building Robust and Reliable Software Jason Anderson, Microsoft jasand@microsoft.com

Static Analysis

• Find errors in your code before you run or deploy it

• Checks range from style to code correctness to security issues

• Integrated into the Team System Build Environment

Page 7: Building Robust and Reliable Software Jason Anderson, Microsoft jasand@microsoft.com

Static AnalysisThe dev process without Static Analysis

CompileCompileCompileCompileCodeCode BinaryBinary

PreprocPreprocPreprocPreproc GrammarGrammarLinkLink

GrammarGrammarLinkLink

RaiseRaiseErrorsErrorsRaiseRaiseErrorsErrors

Chris Lucas
cut
Page 8: Building Robust and Reliable Software Jason Anderson, Microsoft jasand@microsoft.com

Static AnalysisThe dev process with Static Analysis

CodCodee CompileCompileCompileCompile StaticStatic

AnalysisAnalysisStaticStatic

AnalysisAnalysis

AnalyzeAnalyzeCodeCode

AnalyzeAnalyzeCodeCode

CheckCheckRulesRulesCheckCheckRulesRules

RaiseRaiseErrorsErrorsRaiseRaiseErrorsErrors

BinarBinaryy

Chris Lucas
cut
Page 9: Building Robust and Reliable Software Jason Anderson, Microsoft jasand@microsoft.com

Static AnalysisManaged Code Example

static voidstatic void Initialize( Initialize(stringstring id) id) {{ if if (id == "") (id == "") returnreturn;;    trytry     {{      UtilitiesUtilities.OpenUserAccount(id);.OpenUserAccount(id);    }}    catchcatch((ExceptionException ex) ex)    {{      // user must not exist// user must not exist        UtilitiesUtilities.CleanAccountState(id);.CleanAccountState(id); Console.WriteLine(ex);Console.WriteLine(ex);    } } }       }      

CompilesCompilesStatic Analysis Static Analysis gives warnings gives warnings

Page 10: Building Robust and Reliable Software Jason Anderson, Microsoft jasand@microsoft.com

Static AnalysisManaged Code Examplestatic voidstatic void Initialize( Initialize(stringstring id) id) {{ if if (id == "") (id == "") returnreturn;;    trytry     {{      UtilitiesUtilities.OpenUserAccount(id);.OpenUserAccount(id);    }}    catchcatch((ExceptionException ex) ex)    {{      // user must not exist// user must not exist        UtilitiesUtilities.CleanAccountState(id);.CleanAccountState(id); Console.WriteLine(ex);Console.WriteLine(ex);    } } }       }       e:\Logger.cs(39): 'Logger.Initialize(System.String)#System.Void' e:\Logger.cs(39): 'Logger.Initialize(System.String)#System.Void' Modify the following catch clauses in 'Logger.Initialize' Modify the following catch clauses in 'Logger.Initialize' by catching a more specific exception type or rethrowing the by catching a more specific exception type or rethrowing the exception  ' catch(Exception) {...}' exception  ' catch(Exception) {...}'

e:\logger.cs(36): 'Logger.Initialize(System.String)#System.Void' e:\logger.cs(36): 'Logger.Initialize(System.String)#System.Void' Replace all calls to "".Equals or String.Empty.Equals in Replace all calls to "".Equals or String.Empty.Equals in 'Logger.Initialize(System.String)' with checks for Length == 0. 'Logger.Initialize(System.String)' with checks for Length == 0.

Page 11: Building Robust and Reliable Software Jason Anderson, Microsoft jasand@microsoft.com

Static AnalysisManaged Code Examplestatic voidstatic void Initialize( Initialize(stringstring id) id) {{ if if (id.Length == 0)(id.Length == 0) {   throw newthrow new ArgumentExeceptionArgumentExeception(“Bad A…”);(“Bad A…”);  }      trytry     {{      UtilitiesUtilities.OpenUserAccount(id);.OpenUserAccount(id);    }}    catchcatch((ExceptionException ex) ex)    {{      // user must not exist// user must not exist        UtilitiesUtilities.CleanAccountState(id);.CleanAccountState(id); throw throw ex;ex;    } } }       }      

Improve myImprove mycodecode

Page 12: Building Robust and Reliable Software Jason Anderson, Microsoft jasand@microsoft.com

Static AnalysisStatic Analysis

Page 13: Building Robust and Reliable Software Jason Anderson, Microsoft jasand@microsoft.com

ProfilingProfiling

Page 14: Building Robust and Reliable Software Jason Anderson, Microsoft jasand@microsoft.com

Profiling

• Bad performance is expensive● Customer perception● Hardware● Investigation

Page 15: Building Robust and Reliable Software Jason Anderson, Microsoft jasand@microsoft.com

ProfilingInstrumentation

mainmain AMethodAMethod BMethodBMethod

main main 001001AMethodAMethod 00230023BMethodBMethod 00980098…….. .. 01450145

• Adds instructions to your code to monitor

Page 16: Building Robust and Reliable Software Jason Anderson, Microsoft jasand@microsoft.com

ProfilingSampling

mainmain AMethodAMethod BMethodBMethod

• Analyze without changing your app

main 3main 3AMethod 6AMethod 6

BMethod 9BMethod 9

22

Page 17: Building Robust and Reliable Software Jason Anderson, Microsoft jasand@microsoft.com

Profiler

• Able to do both managed and unmanaged

• Able to do both instrumentation and sampling

• Used by many internal teams and on customer engagements

Page 18: Building Robust and Reliable Software Jason Anderson, Microsoft jasand@microsoft.com

ProfilingProfiling

Page 19: Building Robust and Reliable Software Jason Anderson, Microsoft jasand@microsoft.com

Unit TestingUnit Testing

Page 20: Building Robust and Reliable Software Jason Anderson, Microsoft jasand@microsoft.com

Unit Testing• Unit tests are tests written by

programmers to check the functionality of production code● Always automated● Generally one-to-one mapping between

Unit Test and production code

• Typical problems:● Too much overhead for everyone to learn● Too tedious● Isn’t effective enough to warrant the cost● Not process agnostic

Page 21: Building Robust and Reliable Software Jason Anderson, Microsoft jasand@microsoft.com

Writing a Unit Test made Easy

• Low overhead, very few moving parts• We do provide simple helper APIs and

easy to understand attributes• We don’t force inheritance, interfaces,

etc

Page 22: Building Robust and Reliable Software Jason Anderson, Microsoft jasand@microsoft.com

Unit Test Code Generation

• Human error sometimes accounts for missed methods and classes

• Code Generation can develop the skeleton of your unit tests● Namespaces● Classes● Methods

• Generated code fails with result ‘Inconclusive’

Page 23: Building Robust and Reliable Software Jason Anderson, Microsoft jasand@microsoft.com

Unit TestingUnit Testing

Page 24: Building Robust and Reliable Software Jason Anderson, Microsoft jasand@microsoft.com

Test Driven DevelopmentTest Driven Development

Page 25: Building Robust and Reliable Software Jason Anderson, Microsoft jasand@microsoft.com

Test Driven Development

• Think about the code before you write it, have a failing test before you write product code

• The Test Case is a specification● User Scenarios● Business Cases● Minimal bar, boundary conditions,

performance, etc• Infrastructure can be painful

● Build Errors● Managed your failures

Page 26: Building Robust and Reliable Software Jason Anderson, Microsoft jasand@microsoft.com

Test Driven Test Driven DevelopmentDevelopment

Page 27: Building Robust and Reliable Software Jason Anderson, Microsoft jasand@microsoft.com

Code CoverageCode Coverage

Page 28: Building Robust and Reliable Software Jason Anderson, Microsoft jasand@microsoft.com

Code Coverage

• Test Authoring isn’t about quantity, it’s about quality

• Code coverage helps you monitor your tests effectiveness● Team Members can analyze results at a

high-level● Can also analyze source for specific

missed methods and branches

Page 29: Building Robust and Reliable Software Jason Anderson, Microsoft jasand@microsoft.com

Code Coverage

void PurchaseItem(int itemID)

{

if (itemID == 0) {

throw new Exception();

} else

{ ProcessOrder(itemID);

}

}

UnitTest()

{

PurchaseItem(1);

}

Page 30: Building Robust and Reliable Software Jason Anderson, Microsoft jasand@microsoft.com

Code Coverage

void PurchaseItem(int itemID)

{

if (itemID == 0) {

throw new Exception();

} else

{ ProcessOrder(itemID);

}

}

UnitTest()

{

PurchaseItem(1);

}

Page 31: Building Robust and Reliable Software Jason Anderson, Microsoft jasand@microsoft.com

Code Coverage

void PurchaseItem(int itemID)

{

if (itemID == 0) {

throw new Exception();

} else

{ ProcessOrder(itemID);

}

}

UnitTest()

{

PurchaseItem(1);

}

Page 32: Building Robust and Reliable Software Jason Anderson, Microsoft jasand@microsoft.com

Code Coverage

void PurchaseItem(int itemID)

{

if (itemID == 0) {

throw new Exception();

} else

{ ProcessOrder(itemID);

}

}

UnitTest()

{

PurchaseItem(1);

}

Page 33: Building Robust and Reliable Software Jason Anderson, Microsoft jasand@microsoft.com

Code Coverage

void PurchaseItem(int itemID)

{

if (itemID == 0) {

throw new Exception();

} else

{ ProcessOrder(itemID);

}

}

UnitTest()

{

PurchaseItem(1);

}

Page 34: Building Robust and Reliable Software Jason Anderson, Microsoft jasand@microsoft.com

Code Coverage

void PurchaseItem(int itemID)

{

if (itemID == 0) {

throw new Exception();

} else

{ ProcessOrder(itemID);

}

}

UnitTest()

{

PurchaseItem(1);

}

Page 35: Building Robust and Reliable Software Jason Anderson, Microsoft jasand@microsoft.com

Code CoverageCode Coverage

Page 36: Building Robust and Reliable Software Jason Anderson, Microsoft jasand@microsoft.com

Team Developer and Team Developer and Team Foundation ServerTeam Foundation Server

Page 37: Building Robust and Reliable Software Jason Anderson, Microsoft jasand@microsoft.com

Visual Studio Team SystemPro

cess

an

d A

rch

itect

ure

Pro

cess

an

d A

rch

itect

ure

G

uid

an

ceG

uid

an

ce

Vis

ual S

tud

io In

du

stry

V

isu

al S

tud

io In

du

stry

Part

ners

Part

ners

Dynamic Code Analyzer

Visual Studio

Team Architect

Static Code Analyzer

Code Profiler

Unit Testing

Code Coverage

Visio and UML Modeling

Team Foundation Client (includes CAL)

Visual Studio Professional Edition

Class Designer

Load Testing

Manual Testing

Test Case Management

Application Designer

Logical Infra. Designer

Deployment Designer

Visual Studio

Team DeveloperVisual Studio

Team TestDynamic Code Analyzer

Static Code Analyzer

Code Profiler

Unit Testing

Code Coverage

Change Management

Work Item Tracking

Reporting

Project Site

Visual Studio

Team Foundation Integration Services

Project ManagementBig Build

Page 38: Building Robust and Reliable Software Jason Anderson, Microsoft jasand@microsoft.com

Visual Studio Team SystemPro

cess

an

d A

rch

itect

ure

Pro

cess

an

d A

rch

itect

ure

G

uid

an

ceG

uid

an

ce

Vis

ual S

tud

io In

du

stry

V

isu

al S

tud

io In

du

stry

Part

ners

Part

ners

Change Management

Work Item Tracking

Reporting

Project Site

Integration Services

Project Management

Dynamic Code Analyzer

Visual Studio

Team Architect

Static Code Analyzer

Code Profiler

Unit Testing

Code Coverage

Visio and UML Modeling

Team Foundation Client (includes CAL)

Visual Studio Professional Edition

Load Testing

Manual Testing

Test Case Management

Application Designer

Logical Infra. Designer

Deployment Designer

Visual Studio

Team DeveloperVisual Studio

Team Test

Change Management

Work Item Tracking

ReportingVisual Studio

Team Foundation

Class Designer

Big Build

Page 39: Building Robust and Reliable Software Jason Anderson, Microsoft jasand@microsoft.com

Roles Addressed by Team System

Project Manager

Architect Developer Tester

Change Management

Work Item Tracking

Reporting

Project Portal

Visual StudioTeam Foundation

Integration Services

Project Management

Visual Visual Studio Studio IDEIDE

Page 40: Building Robust and Reliable Software Jason Anderson, Microsoft jasand@microsoft.com

Work Item Integration

• Project Management can assign work items and track across lifecycle of the project

• Developers and Testers can assign defects and these integrate with PM work items

• Artifacts (tests, product modules, source code) can be associated with Work Items

Page 41: Building Robust and Reliable Software Jason Anderson, Microsoft jasand@microsoft.com
Page 42: Building Robust and Reliable Software Jason Anderson, Microsoft jasand@microsoft.com

Reviews Find / Fix Rates…

Page 43: Building Robust and Reliable Software Jason Anderson, Microsoft jasand@microsoft.com

..and Daily Trends

Page 44: Building Robust and Reliable Software Jason Anderson, Microsoft jasand@microsoft.com

…and Bugs Against Code Churn and Testing Activity

Page 45: Building Robust and Reliable Software Jason Anderson, Microsoft jasand@microsoft.com

Team Developer

• Static Analysis• Profiling • Unit Testing• Code Coverage• AND MORE!!!• Integrated with TFS

● Source Code Control● Project Management● Bug Tracking● Reports

• All fully functional from the VSTS 2005

Page 46: Building Robust and Reliable Software Jason Anderson, Microsoft jasand@microsoft.com

© 2004 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.