47
Quality Coding: What's New with Visual Studio 2012 The newest release of Visual Studio 2012 is rich with new tools that enhance standard developer activities. In this session, we'll review and demonstrate some of these new features, such as Unit Testing, Code Reviews, Code Clones, and other developer tools. Come join us for this free Webinar!

Quality Coding: What’s New with Visual Studio 2012 (08082013)

Embed Size (px)

DESCRIPTION

The newest release of Visual Studio 2012 is rich with new tools that enhance standard developer activities. In this session, we’ll review and demonstrate some of these new features, such as Unit Testing, Code Reviews, Code Clones, and other developer tools. Come join us for this free Webinar!

Citation preview

Page 1: Quality Coding: What’s New with Visual Studio 2012 (08082013)

Quality Coding: What's New with Visual Studio 2012

The newest release of Visual Studio 2012 is rich with new tools that enhance standard developer activities. In this session, we'll review and demonstrate some of these new features, such as Unit Testing, Code Reviews, Code Clones, and other developer tools. Come join us for this free Webinar!

Page 2: Quality Coding: What’s New with Visual Studio 2012 (08082013)

Agenda

• ALM and Quality

• Quality in Requirements

• Quality in Development– Unit Testing– Fakes– Code Reviews– Code Analysis– Code Clones

• Quality in Test– Manual Testing– Exploratory Testing– Automated Testing– Lab Environments

• Conclusion

Page 3: Quality Coding: What’s New with Visual Studio 2012 (08082013)

Initial Project Portfolio Retire

Recognizing the Iterative Nature of Applications

Define• Requirements• Validation• Prioritization• Release Plan

Develop• Iteration Plan• Develop• Test

Operate• Monitor• Support• Upgrade

Plan

WorkDonePlan

WorkDone

Plan

WorkDone

Plan

WorkDone

Plan

WorkDone

Page 4: Quality Coding: What’s New with Visual Studio 2012 (08082013)

New ALM Capabilities in Visual Studio 2012

Define• Requirements• Validation• Prioritization• Release Plan

Develop• Iteration Plan• Develop• Test

Operate• Monitor• Support• Upgrade

DefineIdeation

OperateDeployment to feedback

DevelopIdea to working software

• PowerPoint Storyboarding• Agile Planning

• Suspend & Resume• Code Reviews• Feedback Collection• Unit Testing• Exploratory Testing• Continuous Integrations• Continuous Deployments

• SCOM Integration• IntelliTrace in Production• PreEmptive Analytics

Page 5: Quality Coding: What’s New with Visual Studio 2012 (08082013)

Quality in Requirements: Storyboarding

• Tighter loop between the Business Stakeholders and Development Team

• Graphical design tools built in PowerPoint

• Embed other content including context slides

• Capture screen shots and create lightweight animations

• Store common elements within a shape library

• Create master templates to simplify multiple similar views

• Get feedback to others– Email, print and version control the

document– leverage collaborative tools– leverage web viewing tools– Integration with TFS

Page 6: Quality Coding: What’s New with Visual Studio 2012 (08082013)

Agenda

• ALM and Quality

• Quality in Requirements

• Quality in Development– Unit Testing– Fakes– Code Reviews– Code Analysis– Code Clones

• Quality in Test– Manual Testing– Exploratory Testing– Automated Testing– Lab Environments

• Conclusion

Page 7: Quality Coding: What’s New with Visual Studio 2012 (08082013)

Why invest in quality?

• Quality is an expensive (and painful) afterthought

RequirementsCoding

IntegrationBeta Test

Post-Release

5

10

15

20

25

30

Relative CostTo Fix Bugs...

Courtesy of the National Institute of Software and Technology (NIST)

Page 8: Quality Coding: What’s New with Visual Studio 2012 (08082013)

Problems...

• It is expensive to find and fix bugs that get past daily development practices

• It is hard to diagnose errors at runtime• Why does an application run slowly?• Individual Developers and Testers need to know if

they are on track• Test and development are often out of synch• Final test phase for shipping is often ad-hoc• How much testing is enough?

Page 9: Quality Coding: What’s New with Visual Studio 2012 (08082013)

Approach for Development Quality

• Use 'defence in depth' strategy– Unit testing– Code reviews– Continuous integration builds / Gated Check-ins– Static Code Analysis– Education / Patterns / Best Practices

Page 10: Quality Coding: What’s New with Visual Studio 2012 (08082013)

Unit Testing Runner

New Test Runner:• Tests run in background• Run automatically on build• Support for multiple unit

testing frameworks:– MS Test– xUnit– nUnit– And More!

• Deep integration in the IDE• Supports native C++ code• Multiple run options

– Failed Tests– Not-run Tests– All Tests

• Easy code coverage access

Page 11: Quality Coding: What’s New with Visual Studio 2012 (08082013)

public double MethodA() { ... }

Unit Testing

• Diagnostic checks during development– Automated test script for methods on a type– Basic sanity checking– Useful for regression testing

public void TestMethodA(){ SomeClass c = new SomeClass(); // Arrange double d = c.MethodA(); // Act Assert.AreEqual(expected, d); // Assert}

Each

meth

od

has

on

e o

r more

corre

sp

on

din

g

test m

eth

od

s

Page 12: Quality Coding: What’s New with Visual Studio 2012 (08082013)

Use the framework you want to use

• In the box support for– .NET – Native C/C++

• Third party plugins– NUnit– xUnit.net– MbUnit– QUnit/Jasmine– SQL Server Unit Testing

(Under development)

Page 13: Quality Coding: What’s New with Visual Studio 2012 (08082013)

MS-Test Improvements

• Many performance and scale improvements– Especially when you stick to “classic” unit testing

• Support for testing Async[TestMethod]public async Task MyAsyncTest(){ var result = await SomeLongRunningOperation(); Assert.IsTrue( result );}

• Proper support for 64-bit and .Net multi-targeting• Available in Express!

Page 14: Quality Coding: What’s New with Visual Studio 2012 (08082013)

Continuous Testing

• “If you aren’t running your unit tests, you are just compiling. You are not building.”

• Chris PattersonProgram ManagerTeam Foundation Build

• Run Tests After Build option in Visual Studio 2012 will run your Unit Tests after each successful build of your solution

Page 15: Quality Coding: What’s New with Visual Studio 2012 (08082013)

Code coverage in VS 2012

• Analyze your code coverage with a single click

• Analyze for selected tests to help find how specific tests are covering your system

• Supports all managed & native frameworks

Page 16: Quality Coding: What’s New with Visual Studio 2012 (08082013)

DEMONSTRATION

• Unit Test Basics

• Unit Test Explorer

• Framework Plug-Ins

• Continuous Testing

• Code Coverage

• Play Lists (Update 2)

Page 17: Quality Coding: What’s New with Visual Studio 2012 (08082013)

What’s missing?

• Test Lists– Legacy mode only

• Test Impact– Works on the server, not in

the VS client

• Private Accessors– Deprecated in VS 2010,

removed in VS 2012

• Generate Unit Test– Didn’t actually generate a

unit test

Page 18: Quality Coding: What’s New with Visual Studio 2012 (08082013)

Unit Testing and Isolation

• Unit Tests verify the smallest testable ‘unit’ of code• Target code should be isolated from external

influences• Unit Test frameworks can perform integration testing

Target Pseudo-Code:Function DoSomething(a) x = LookupInDatabase(a) y = ProcessWithWebService(x) LogToFile(“Processing complete”)End Function

Unit Test Pseudo-Code: T = new SomeClass() result = T.DoSomething(1) Assert.AreEqual(2,result)End Function

Response controlled by test

Response controlled by test

Response controlled by test

Page 19: Quality Coding: What’s New with Visual Studio 2012 (08082013)

What is un-testable code?

Where do we find it?

• “Get ‘er done” code– Business logic in code-behind– Classes with too many

dependencies– Database logic mixed with

business logic

• Testability was not a consideration– Or was explicitly avoided

• Monolithic, highly-coupled designs

Common indicators

• Complex test setup and teardown• Environmental dependencies• Public static methods• Hidden object creation• Complex external frameworks• No tests at all!

Any system where the tests require complex setup or where the tests run very slowly is unsuitable for the kind of

developer testing we really care about.

Page 20: Quality Coding: What’s New with Visual Studio 2012 (08082013)

void FileExistsTest() { File.Write("foo.txt", ""); var result = IsFileEmpty("foo.txt") Assert.IsTrue(result);}

File.Write("foo.txt", "");

A simple test setup example

The method we want to unit test

bool IsFileEmpty(string file) { var content = File.ReadAllText(file); return content.Length == 0;}

File.ReadAllText(file);

Is this a “good” test?

…this ugly setup code

This dependency forces…

Page 21: Quality Coding: What’s New with Visual Studio 2012 (08082013)

Environmental Dependencies

Consider the following Y2K code:

public void ThrowIfEndOfTheWorld() { if (DateTime.Now == new DateTime(2000,1,1)) throw new Y2KBugException();}

How would you test it reliably?

Page 22: Quality Coding: What’s New with Visual Studio 2012 (08082013)

[DllImport("kernel32.dll")]extern static bool SetSystemTime(ref SystemTime time);

[TestMethod]public void Y2KTest(){ SetSystemTime(2000,1,1,0,0,0); Assert.Throws( () => ThrowIfEndOfTheWorld() );}

Environmental Dependencies

How about this? Why is this bad?

Page 23: Quality Coding: What’s New with Visual Studio 2012 (08082013)

Isolating code with Microsoft Fakes

• Visual Studio 2012 Fakes lets you isolate almost any .NET

• Fakes come in two flavors

– Stubs: concrete implementations of interfaces or abstract classes

– Shims: run-time interception lets you replace calls, even those from the .NET BCL

Page 24: Quality Coding: What’s New with Visual Studio 2012 (08082013)

Visual Studio 2012 Shims – Be Cautious

• Runtime interception of any .NET method– Uses the profiler to detour calls– “Monkey patching” for .NET

• Use it when you…– Have external components that cannot be

refactored• SharePoint, ASP.NET, Office, etc.

– Need to override non-virtual methods• Static methods, constructors, sealed types,

properties

– Have legacy code with untestable designs

Page 25: Quality Coding: What’s New with Visual Studio 2012 (08082013)

SharePoint Development Enhancements

• SharePoint improvements (Update 2)– Unit test emulator– Coded UI test support– Web Performance test support– Load test support– IntelliTrace collection plan

Page 26: Quality Coding: What’s New with Visual Studio 2012 (08082013)

SharePoint and Unit Testing[TestMethod]      public  void ScheduleAppointmentReturnsTrueWhenNewAppointmentIsCreated()      {          using (new SharePointEmulationScope(EmulationMode.Enabled))          {              //Arrange SPSite site = new SPSite("http://localhost");            string listName = String.Format("List{0}", Guid.NewGuid());        // create a new temporary list              Guid listId = site.RootWeb.Lists.Add listName, listName, SPListTemplateType.GenericList);              SPList list = site.RootWeb.Lists[listId];              Assert.IsNotNull(list); // add fields to list              list.Fields.Add("Name", SPFieldType.Text, true);              list.Fields.Add("Date", SPFieldType.Text, false);         list.Update();        // prepare         string errorMsg = string.Empty;         DateTime date = DateTime.Now;         BookAnAppointmentWebPart webPart = new BookAnAppointmentWebPart();

        // Act         bool success = webPart.ScheduleAppointment(site.RootWeb, list.Title, "My Name",                        "888-888-8888", "[email protected]", "23", date, out errorMsg);        // Assert         Assert.IsTrue(success);

        // cleanup         list.Delete();         site.Dispose();     } }

Page 27: Quality Coding: What’s New with Visual Studio 2012 (08082013)

Code Reviews

Purpose:– Find and fix bugs early in the process

(much cheaper and easier than later)– Adherence to development standards– Improve consistency– Improve comments and maintainability– Share best practices across the team– Educate both experienced and new team

members

– Improve overall structural quality of the code and skillset of the team!

Page 28: Quality Coding: What’s New with Visual Studio 2012 (08082013)

Integrated Code Review

• Provides feedback from other team members

• Shared knowledge across team

• Code reviews can be set as a quality gate

• Source changes highlighted and comments about the changes.

Page 29: Quality Coding: What’s New with Visual Studio 2012 (08082013)

Automated Reviews?

• Static Code Analysis:– Analyze code (MSIL/SQL) based

on best practices (rules)– Rules created by and used at Microsoft– Rulesets:

• Selectable groups of rules allow tailoring to your environment• Rulesets can be further customized for the exact rules you need

– Can support both T-SQL and .NET– Can be ‘enforced’ using check-in policies– Can be reported during the build (including CI and Gated)

• Still not the same as manual/peer reviews

Page 30: Quality Coding: What’s New with Visual Studio 2012 (08082013)

Code Clone Detection

• Reviews common code blocks exposing refactoring opportunities

• Detect code blocks with common structure and approach

• Search is semantic, not just literal

• Detects ‘copy and paste’ errors

• Detects code fragments with a common logical structure

• Review common code and decide how to proceed

Page 31: Quality Coding: What’s New with Visual Studio 2012 (08082013)

DEMONSTRATION

Code Reviews

Code Comparison

Static Analysis

Page 32: Quality Coding: What’s New with Visual Studio 2012 (08082013)

Agenda

• ALM and Quality

• Quality in Requirements

• Quality in Development– Unit Testing– Fakes– Code Reviews– Code Analysis– Code Clones

• Quality in Test– Manual Testing– Exploratory Testing– Automated Testing– Lab Environments

• Conclusion

Page 33: Quality Coding: What’s New with Visual Studio 2012 (08082013)

Tester Enhancements in Visual Studio 2012

• Microsoft Test Manager– Performance– Exploratory Testing– Clone test suites via command line ("versioning")– Multi-line test steps– Rich-text in test steps– Improved Test Step grid usability– Read-only test case access from within Test Runner– Pass/Fail test cases without using Test Runner– Enhanced view of results for Test Plan– Manual testing for Metro-style applications– Code Coverage for Manual Testing (Update 1)– Suspend/Resume testing for test case development

• Coded UI Testing– UI Map Access– Cross Browser UI Testing (Update 1)– Test data reduction through test settings configuration

• Team Web Access - Test Hub

Page 34: Quality Coding: What’s New with Visual Studio 2012 (08082013)

Web Access – Test Hub

Page 35: Quality Coding: What’s New with Visual Studio 2012 (08082013)

Initiating Exploratory Testing

or no work item.

Explore based on specific work item(s)…

Page 36: Quality Coding: What’s New with Visual Studio 2012 (08082013)

Performing Exploratory Testing

• Familiar Test Runner interface customized for exploratory testing

• Free-form comment area allows tester to record suggestions and problems encountered during the session

• Comment area allows for rich-text, attachments, and easy insertion of screenshot

• Session can be paused to perform activities outside of the Test Runner

• Bug and Test Case work items can readily be created during the exploratory testing session

Page 37: Quality Coding: What’s New with Visual Studio 2012 (08082013)

Coded UI – UI Map Editor

It’s in the box now!

Page 38: Quality Coding: What’s New with Visual Studio 2012 (08082013)

DEMONSTRATION

Exploratory Testing

Cross-browser Coded UI Testing

Page 39: Quality Coding: What’s New with Visual Studio 2012 (08082013)

Questions?

Page 40: Quality Coding: What’s New with Visual Studio 2012 (08082013)

Want to know more...?

Page 41: Quality Coding: What’s New with Visual Studio 2012 (08082013)

Imaginet’s New Blog Keeps You In The Know

http://blog.imaginet.com

Stay up to speed on the latest news from Imaginet, Microsoft, Visual Studio, and the entire software development world.

Page 42: Quality Coding: What’s New with Visual Studio 2012 (08082013)

More Webcasts on ALM / TFS / Visual Studio 2012

• Quality Coding: What’s New with Visual Studio 2012• April 18 (1:00-2:30pm CT)• May 9 (1:00-2:30pm CT)• May 23 (1:00-2:30pm CT)

• Getting Started With Coded UI testing: Building Your First Automated Test• April 11 (1:00-2:30pm CT)• April 25 (1:00-2:30pm CT)• June 13 (1:00-2:30pm CT)• June 27 (1:00-2:30pm CT)

• The How, What, and Why of Performance Testing Your Applications• May 2 (1:00-2:30pm CT)

• Top Business Benefits of Application Lifecycle Management (ALM)• June 3 (1:00-2:00pm CT)

• Managing Test Labs Without the Headaches• June 6 (1:00-2:30pm CT)• June 20 (1:00-2:30pm CT)

Page 43: Quality Coding: What’s New with Visual Studio 2012 (08082013)

Free Services from Imaginet & Microsoft

There are a number of different Microsoft Programs that you might be able to leverage to get some free services from Imaginet:

• Deployment Planning Services (DPS) – You can trade in your Microsoft Software Assurance credits to receive some free TFS/ALM Deployment Planning Services days with Imaginet

• Partner Services Credit (PSC) – Have you or are you about to spend money with Microsoft on Visual Studio 2012 products? If so, Microsoft may kick in some funding to help you successfully adopt.

• Virtual Technical Specialist (VTS) hours –You may be eligible to receive some free remote consulting/training hours with Imaginet through the Microsoft Virtual Technical Specialist program.

For more information, email [email protected].

Page 44: Quality Coding: What’s New with Visual Studio 2012 (08082013)

Need Help with YOUR Automated Testing?

• Learn best practices for test selection, extension, data binding, maintenance, frameworks, community extensions (such as the CUITe and the UI Map Toolbox), and other real-world scenarios.

• Includes automated test development & execution for YOUR application

• Support and training for your team

• Includes a high-level ALM assessment

Imaginet’s Visual Studio 2012Automated Testing 5-day Quickstart

Interested? Just email us at [email protected].

Page 45: Quality Coding: What’s New with Visual Studio 2012 (08082013)

Email us at:[email protected]

ALM Planning & Implementation ServicesALM Planning • ALM Assessment & Envisioning Workshops

(3 or 5 days)• VS & TFS Migration Planning Workshop (5

days)• TFS Deployment Planning* (5 days)• Visual SourceSafe to TFS Migration

Planning* (3 Days)• Visual Studio Quality Tools Deployment

Planning* (5 days)

Upgrade• TFS 2010 Adoption Quick Start (5 or 10

days)• TFS 2012 Adoption Quick Start (5 or 10

days)• TFS 2010 Upgrade Quick Start (10 days)• TFS 2012 Upgrade Quick Start (10 days)

Remote Support• Remote Support for TFS & Visual Studio

Lab• Visual Studio Lab Management Quick Start

(10 days)

Testing• Manual Testing with Test Manager Quick

Start (5 days)• Visual Studio Testing Tools Quick Start (10

days)• Visual Studio Automated Testing Quick Start

(5 days)• Visual Studio Load Testing Quick Start (5 or

10 Days)

Builds• Automated Build & Release Management

Quick Start (5 days)• Automated Build Center of Excellence (CoE)

Database• Visual Studio Database Tools Quick Start (10

days)

Integrations• Team Foundation Server (TFS) & Project

Server Integration Quick Start (10 days)• TFS & Quality Center Integration/Migration

Quick Start (10 days)

Page 46: Quality Coding: What’s New with Visual Studio 2012 (08082013)

For questions or more information,please contact us at:

[email protected] or (972)607-4830

Remember to add http://blog.imaginet.com to your favorite reader!

Page 47: Quality Coding: What’s New with Visual Studio 2012 (08082013)

http://www.imaginet.com