23
.NET Code Coverage for Continuous Integration using TeamCity and dotCover Maarten Balliauw Technical Evangelist [email protected] @ maartenballiauw

NET Code Coverage for Continuous Integrationusing TeamCity and dotCover

Embed Size (px)

DESCRIPTION

How much of our code is being covered by our unit tests? Are there areas we are not testing? By capturing code coverage data during a test run, we can analyze which areas of our applications are well-tested and which ones require additional tests to be written. And where better to capture code coverage information than on our build server? In this webinar we will use dotCover to collect code coverage information while running tests in our CI process. We will see how we can configure code coverage and how we can use the TeamCity Visual Studio plugin to download the coverage snapshot generated on the build server and inspect it using dotCover on a developer machine.

Citation preview

Page 1: NET Code Coverage for Continuous Integrationusing TeamCity and dotCover

.NET Code Coverage for Continuous Integrationusing TeamCity and dotCoverMaarten BalliauwTechnical [email protected] @maartenballiauw

Page 2: NET Code Coverage for Continuous Integrationusing TeamCity and dotCover

Who am I? Maarten Balliauw

Belgium (Antwerp)

Technical Evangelist, JetBrains

Focus on web ASP.NET MVC, Windows Azure, ... PHP, ...

Big passion: Cloud (Windows Azure)

Home brewer

http://blog.maartenballiauw.be

@maartenballiauw

Page 3: NET Code Coverage for Continuous Integrationusing TeamCity and dotCover

Have a question? Use the Question Pane. We’ll try and answer as we go along.

Page 4: NET Code Coverage for Continuous Integrationusing TeamCity and dotCover

Recording

Recording will start now….

Page 5: NET Code Coverage for Continuous Integrationusing TeamCity and dotCover

Agenda Code coverage

dotCover

Code coverage during CI

Command line runner

TeamCity integration

TeamCity service messages

TeamCity Visual Studio plugin

Page 6: NET Code Coverage for Continuous Integrationusing TeamCity and dotCover

Code Coverage

“Code coverage is a measure used to describe the degree to which the source code of a program is tested by a particular test suite.”

Wikipedia - http://en.wikipedia.org/wiki/Code_coverage

Page 7: NET Code Coverage for Continuous Integrationusing TeamCity and dotCover

dem

o

Code CoverageUsing dotCover to capture Code Coverage

Page 8: NET Code Coverage for Continuous Integrationusing TeamCity and dotCover

Holy grail? Code Coverage is just a tool Verify # of statements executed during a test run

100% coverage != 100% bug free / well-tested code It’s relatively easy to cover all lines of code It’s much harder to test them correctly Should we aim for 100%?

We should care about code coverage! Identify parts of code not covered by any type of test and reduce

chance of defects

Page 9: NET Code Coverage for Continuous Integrationusing TeamCity and dotCover

dotCover Capture which statements have been executed (using profiler) During unit test During manual test

Display coverage percentage

Statement level coverage visualization

Hotspots to quickly identify parts that need testing

Filtering, exporting, ...

Navigate between code and test

Command line runner

Page 10: NET Code Coverage for Continuous Integrationusing TeamCity and dotCover

dem

o

dotCover 101A quick look at dotCover

Page 11: NET Code Coverage for Continuous Integrationusing TeamCity and dotCover

When to perform code coverage? Let’s counter that with a question: When to run unit tests?

On developer machine is always nice, but… Continuous Integration is our view of the truth Compile, Run tests, Code coverage, …

Page 12: NET Code Coverage for Continuous Integrationusing TeamCity and dotCover

TeamCity JetBrains Continuous Integration Server Project Logical name/unit Build Configuration Something we want to run Build Steps Various steps we want to run (like compilation or unit tests, .NET, Java, deployment,

…) Build Execution log and artifacts of a build configuration after run

Integrated build step for running NUnit + code coverage using dotCover

Page 13: NET Code Coverage for Continuous Integrationusing TeamCity and dotCover

dem

o

TeamCity 101A quick look at TeamCity

Page 14: NET Code Coverage for Continuous Integrationusing TeamCity and dotCover

TeamCity Service Messages Test resuls from xUnit were reported using TeamCity Service Messages

http://confluence.jetbrains.com/display/TCD8/Build+Script+Interaction+with+TeamCity#BuildScriptInteractionwithTeamCity-Reporting.NETCodeCoverageResults

##teamcity[testStarted name='testName' captureStandardOutput='<true/false>']##teamcity[testFinished name='testName' duration='<test_duration_in_milliseconds>']

We can report coverage using this technique as well!##teamcity[importData type='dotNetCoverage' tool='dotcover' path='coverage.xml'

Now all we need is way to run tests with coverage...

Page 15: NET Code Coverage for Continuous Integrationusing TeamCity and dotCover

dotCover Command Line Runner dotcover.exe Create configuration (which executable, which assemblies, …) Run dotcover.exe with that configuration Export to XML, HTML, …

Page 16: NET Code Coverage for Continuous Integrationusing TeamCity and dotCover

dem

odotCovercommand line runnerUsing the command line runner

Page 17: NET Code Coverage for Continuous Integrationusing TeamCity and dotCover

dem

o

TeamCity pluginfor Visual StudioMaking the story complete

Page 18: NET Code Coverage for Continuous Integrationusing TeamCity and dotCover

Conclusion Code coverage

dotCover

Code coverage during CI

Command line runner

TeamCity integration

TeamCity service messages

Visual Studio Plugin

Page 19: NET Code Coverage for Continuous Integrationusing TeamCity and dotCover

Questions

Leading by example

Page 20: NET Code Coverage for Continuous Integrationusing TeamCity and dotCover

Resources Try dotCover now! http://www.jetbrains.com/dotcover

Tutorials Getting started

http://confluence.jetbrains.com/display/NETCOM/Getting+Started+with+dotCover

Command line runner http://confluence.jetbrains.com/display/NETCOM/How+to+Run+Code+Coverage+from+Command+Line+in+dotCover

dotCover in TeamCity http://confluence.jetbrains.com/display/NETCOM/How+to+Run+Code+Coverage+with+dotCover+in+TeamCity

TeamCity Service Messageshttp://confluence.jetbrains.com/display/TCD8/Build+Script+Interaction+with+TeamCity#BuildScriptInteractionwithTeamCity-Reporting.NETCodeCoverageResults

Page 21: NET Code Coverage for Continuous Integrationusing TeamCity and dotCover

More info

Home

FeedbackVideosBlog

http://jetbrains.com/dotcover

[email protected]://youtrack.jetbrains.com/

issues/DCVRhttp://www.youtube.com/

jetbrainstv.NET Tools Channelhttp://blog.jetbrains.com/dotnet

Page 22: NET Code Coverage for Continuous Integrationusing TeamCity and dotCover

Thank you for joining us!

Want to learn more?

Follow @dotcover on Twitter

to learn product tips and register for upcoming

webinars

Page 23: NET Code Coverage for Continuous Integrationusing TeamCity and dotCover