Dave Lloyd Unit Testing in the Real World.

15
Dave Lloyd www.ObjectSharp.com/Blogs/Dave Unit Testing in the Real World

Transcript of Dave Lloyd Unit Testing in the Real World.

Page 1: Dave Lloyd   Unit Testing in the Real World.

Dave Lloydwww.ObjectSharp.com/Blogs/Dave

Unit Testing in the Real World

Page 2: Dave Lloyd   Unit Testing in the Real World.

AgendaAgenda

Anatomy of a Test FixtureBeware of the .VSMDIUsing the .testrunconfigExpected ExceptionsData Driven TestsMock ObjectsIgnore & InconclusiveTest Driven DevelopmentStatic Code Analysis and Code Coverage

Page 3: Dave Lloyd   Unit Testing in the Real World.

Anatomy of a TestFixture

Test Class<TestClass><ClassInitialize()> and <ClassCleanup()><TestInitialize()> and <TestCleanup()>

Test Method<TestMethod()>

TestContext Property

Page 4: Dave Lloyd   Unit Testing in the Real World.

.VSMDI

Meta Data for Test ManagerMust have VS for Testers or Team SuiteNot a part of VS for Developers

Don’t Merge this file!To add tests to a Team Build you need this file

Page 5: Dave Lloyd   Unit Testing in the Real World.

.testrunconfig

Creating and using your ownDeploymentCode CoverageSetup and Cleanup Batch Files

Page 6: Dave Lloyd   Unit Testing in the Real World.

Testing for Expected Exceptions

ExpectedException AttributeValidate the correct Exception was raised

Page 7: Dave Lloyd   Unit Testing in the Real World.

Data Driven Tests

DataSource AttributeExecute a test using test data

Page 8: Dave Lloyd   Unit Testing in the Real World.

Mock Objects

The Crash Test Dummies of Unit TestingSimulated ObjectSame Interface as the Real Object

Why Create a Mock ObjectReal one doesn’t exist yetDifficult to produce within a test

Page 9: Dave Lloyd   Unit Testing in the Real World.

Ignore & Inconclusive

IgnoreTell VSTS to ignore a test

Assert.InconclusiveShow test in test results with messageReminder of an Inconclusive Test

Page 10: Dave Lloyd   Unit Testing in the Real World.

Test Driven Development

Available in C#The Process

Write a Test Execute and see it failWrite the codeExecute the test and see it pass

Smart Tag allowing you to Generate a method Stub in the code being tested

Page 11: Dave Lloyd   Unit Testing in the Real World.

Code Coverage

Page 12: Dave Lloyd   Unit Testing in the Real World.

Static Code Analysis

Page 13: Dave Lloyd   Unit Testing in the Real World.

AdditionalResources

Blogs on TDD:• James Newkirk - blogs.msdn.com/jamesnewkirk• Brian Marick - www.testing.com/cgi-bin/blog• Jonathan de Halleux - http://blog.dotnetwiki.org/ • Jose Almeida - blogs.msdn.com/josealmeida/• Scott Densmore – blogs.msdn.com/scottdensmore• Code Project -www.codeproject.com/dotnet/tdd_in_dotnet.asp• TestDriven.com - www.testdriven.com

Books:• Test-Driven Development in Microsoft.Net

By James W. Newkirk & Alexei A. Vorontsov• Test Driven Development: A Practical Guide

By David Astels• Test Driven Development: by Example

By Kent Beck

Page 14: Dave Lloyd   Unit Testing in the Real World.

Unit Testing in the Real World

Dave LloydPartner, ObjectSharp Consultingwww.ObjectSharp.com/Blogs/Dave

Page 15: Dave Lloyd   Unit Testing in the Real World.

Unit Testing in the Real World

Dave Lloydwww.ObjectSharp.com/Blogs/Dave