Automated Builds And UI Testing in SharePoint 2010 Development

34
BEST PRACTICES CONFERENCE SHAREPOINT Clarity. Direction. Confidence. AUTOMATED BUILDS AND UI TESTING IN SP2010 DEVELOPMENT Chris O’Brien DEV203

description

Shows how to introduce automated builds and UI testing to SharePoint 2010 development projects. Team Foundation Server 2010 is used as the build platform. Includes coverage of VS2010 features such as code profiling, IntelliTrace etc.

Transcript of Automated Builds And UI Testing in SharePoint 2010 Development

Page 1: Automated Builds And UI Testing in SharePoint 2010 Development

BEST PRACTICES CONFERENCE SHAREPOINT

Clarity. Direction. Confidence.

AUTOMATED BUILDS AND UI TESTING IN

SP2010 DEVELOPMENT

Chris O’Brien

DEV203

Page 2: Automated Builds And UI Testing in SharePoint 2010 Development

BEST PRACTICES CONFERENCE SHAREPOINT

About me

Independent SharePoint consultant

Blog: www.sharepointnutsandbolts.com

Twitter: @ChrisO_Brien

Book: Real World SharePoint 2010 (20 MVPs)

LinkedIn: http://uk.linkedin.com/in/chrisobrienmvp

Page 3: Automated Builds And UI Testing in SharePoint 2010 Development

BEST PRACTICES CONFERENCE SHAREPOINT

Problems in SP2010 dev projects

Many dependenciesCode, Features, timer jobs

Deployment is complexe.g. No native support for WSP rollback

Difficult to unit testStill not much traction in SharePoint world?

Page 4: Automated Builds And UI Testing in SharePoint 2010 Development

BEST PRACTICES CONFERENCE SHAREPOINT

Problems in *large* SP2010 dev projects

TrackingHard to keep track of deployments/fixes

Many developers = many deployments?

InefficiencyDevs keeping environment up-to-date

Inconsistent builds (or buildmaster bottleneck)Silly mistakes e.g.

Incorrect versions

Debug vs. Release mode

Testing of actual WSPs

Communication

Page 5: Automated Builds And UI Testing in SharePoint 2010 Development

BEST PRACTICES CONFERENCE SHAREPOINT

Solution recipe

Auto-compile of assemblies and build of WSPsCorrect versions in source control

Add a label in source control to help rollback

Auto incrementing assembly version numberBetter tracking of deployments/fixes etc.

Deployment of WSPs to remote SharePoint 2010 environment

Test environment, not developer machine

UI testingBuild fails on UI test failure

Developer notifications

Page 6: Automated Builds And UI Testing in SharePoint 2010 Development

BEST PRACTICES CONFERENCE SHAREPOINT

Solution ingredients

TFS Team Build workflow (.Net 4.0)Specifies sequence of steps

PowerShellDeploys WSPs, other deployment steps e.g. teardown/setup site

PowerShell remoting (preferred over PsExec)

Allows PS on SharePoint box to be called from build server

Invoke-Command -ComputerName “foo” { script }

Skills• “Good enough”

PowerShell

• “Good enough” workflow (3.5 OK)

Page 7: Automated Builds And UI Testing in SharePoint 2010 Development

BEST PRACTICES CONFERENCE SHAREPOINT

AUTOMATING THE BUILD

Page 8: Automated Builds And UI Testing in SharePoint 2010 Development

BEST PRACTICES CONFERENCE SHAREPOINT

Build definition

Styles:

What’s the trigger?Manual, Scheduled (e.g. nightly), every check-in, Rolling builds, Gated Check-In etc.

Customise workflowMandatory for SharePoint builds

Several workflows OOTBDefaultTemplate, LabTemplate

“Rebuild everything” Suits pre-live

“Build current sprint against production state”

Suits post-live

Page 9: Automated Builds And UI Testing in SharePoint 2010 Development

BEST PRACTICES CONFERENCE SHAREPOINT

Clarity. Direction. Confidence.

DEMOAutomating the build

Page 10: Automated Builds And UI Testing in SharePoint 2010 Development

BEST PRACTICES CONFERENCE SHAREPOINT

Image: selecting build trigger

Page 11: Automated Builds And UI Testing in SharePoint 2010 Development

BEST PRACTICES CONFERENCE SHAREPOINT

Image: customizing build workflow

Page 12: Automated Builds And UI Testing in SharePoint 2010 Development

BEST PRACTICES CONFERENCE SHAREPOINT

CODED UI TESTS

Page 13: Automated Builds And UI Testing in SharePoint 2010 Development

BEST PRACTICES CONFERENCE SHAREPOINT

What is a coded UI test?

Recorded on test agent desktopSupport: browser (inc. AJAX), Silverlight, WPF, forms apps

Generate code which can be modified (e.g. to pass data)

Point and click to add assertionsE.g. navigate to web part gallery, check web part present

Page 14: Automated Builds And UI Testing in SharePoint 2010 Development

BEST PRACTICES CONFERENCE SHAREPOINT

Clarity. Direction. Confidence.

DEMOTesting SharePoint with coded UI tests

Page 15: Automated Builds And UI Testing in SharePoint 2010 Development

BEST PRACTICES CONFERENCE SHAREPOINT

Image: recording a UI test

Page 16: Automated Builds And UI Testing in SharePoint 2010 Development

BEST PRACTICES CONFERENCE SHAREPOINT

ADDING CODED UI TESTS TO THE BUILD

Page 17: Automated Builds And UI Testing in SharePoint 2010 Development

BEST PRACTICES CONFERENCE SHAREPOINT

Integrating coded UI tests into build

Automatic if test assembly name matches filespecDefault = “*test*” somewhere in assembly name

Background:All tests can be run from command-line with MSTest.exe (Unit tests, Coded UI tests, Load tests, Etc.)

Team Build ships with MSTest WF activity (wrapper)

The OOTB workflows contain this activity

Caveat:OOTB workflows must be edited to deploy WSPs and/or run coded UI tests

Page 18: Automated Builds And UI Testing in SharePoint 2010 Development

BEST PRACTICES CONFERENCE SHAREPOINT

Clarity. Direction. Confidence.

DEMOCatching code issues with build/test

process

Page 19: Automated Builds And UI Testing in SharePoint 2010 Development

BEST PRACTICES CONFERENCE SHAREPOINT

Image: build summary

Page 20: Automated Builds And UI Testing in SharePoint 2010 Development

BEST PRACTICES CONFERENCE SHAREPOINT

Image: test results for build

Page 21: Automated Builds And UI Testing in SharePoint 2010 Development

BEST PRACTICES CONFERENCE SHAREPOINT

Image: analyzing failed test (1)

Page 22: Automated Builds And UI Testing in SharePoint 2010 Development

BEST PRACTICES CONFERENCE SHAREPOINT

Image: analyzing failed test (2)

Page 23: Automated Builds And UI Testing in SharePoint 2010 Development

BEST PRACTICES CONFERENCE SHAREPOINT

Why stop at UI testing?

Code profiling

Code analysis Unit tests

SPDispose Check IntelliTrace Load tests

(maybe!)

Test recordings

Collecting system/event

log data

Page 24: Automated Builds And UI Testing in SharePoint 2010 Development

BEST PRACTICES CONFERENCE SHAREPOINT

Image: code profiling in build (1)

Page 25: Automated Builds And UI Testing in SharePoint 2010 Development

BEST PRACTICES CONFERENCE SHAREPOINT

Image: code profiling in build (2)

Page 26: Automated Builds And UI Testing in SharePoint 2010 Development

BEST PRACTICES CONFERENCE SHAREPOINT

Image: IntelliTrace in build

Page 27: Automated Builds And UI Testing in SharePoint 2010 Development

BEST PRACTICES CONFERENCE SHAREPOINT

Best practices

Start on day 0 of projectRetro-fitting can be expensive

Get fast feedback - have a lightweight/quick build run on check-in

Compile all projects/build WSPs

Suggestion - every SharePoint project should do this much

Increment assembly versions (FileVersion) with label generated by build

Leverage UI testing (with or without automated builds)

Page 28: Automated Builds And UI Testing in SharePoint 2010 Development

BEST PRACTICES CONFERENCE SHAREPOINT

Resources

Setting up TFS to build SharePoint Projects - http://bit.ly/9lEqnP

Assembly versions in build workflow - http://bit.ly/eRPB0e

Running tests as part of a build - http://bit.ly/i41eze

PS remoting and SharePoint 2010 - http://bit.ly/9Cb4tF

Also on my blog soon:My customized workflow and PS scripts

Multi-part article series on automated builds/testing

www.sharepointnutsandbolts.com

Page 29: Automated Builds And UI Testing in SharePoint 2010 Development

BEST PRACTICES CONFERENCE SHAREPOINT

Clarity. Direction. Confidence.

THANK YOU!

Page 30: Automated Builds And UI Testing in SharePoint 2010 Development

BEST PRACTICES CONFERENCE SHAREPOINT

Clarity. Direction. Confidence.

APPENDIX SLIDES

Page 31: Automated Builds And UI Testing in SharePoint 2010 Development

BEST PRACTICES CONFERENCE SHAREPOINT

What you need - software

Automated builds = TFS 2010 (Team Build)Server + 1 CAL free with every MSDN level

Need CAL for every user who interacts

Components: Build Controller, Build Agent

Coded UI tests = Visual Studio 2010 Premium/Ultimate (OR ‘Test Elements’ add-on)

Components: Test Controller, Test Agent

Page 32: Automated Builds And UI Testing in SharePoint 2010 Development

BEST PRACTICES CONFERENCE SHAREPOINT

What you need - hardware

Disadvantages:Risk to source control

Performance

SP2010 + TFS2010 = big resource reqs

Bottom line:Don’t do this with prod source control!

Option 1 – the EASY button

Page 33: Automated Builds And UI Testing in SharePoint 2010 Development

BEST PRACTICES CONFERENCE SHAREPOINT

What you need - hardwareOption 2 – a sample topology

Page 34: Automated Builds And UI Testing in SharePoint 2010 Development

BEST PRACTICES CONFERENCE SHAREPOINT

PowerShell remoting

To enable:

To run:Invoke-Command -ComputerName “foo” { script }

Task PS command/Action

Allow remote connections Enable-PSRemoting

Raise memory limit (e.g. for WSP cmds)

Set-Item WSMan:\localhost\Shell\MaxMemory PerShellMB 1000

Allow users from other domain Set registry key

Enable CredSSP authentication http://bit.ly/9Cb4tF