Quality Coding: What’s New with Visual Studio 2012

807 views
682 views

Published on

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!

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
807
On SlideShare
0
From Embeds
0
Number of Embeds
37
Actions
Shares
0
Downloads
5
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • This is the teaser for the class – we will preview (in slides) many of the topics that we’ll dive into deeply as part of this training class…
  • This is the teaser for the class – we will preview (in slides) many of the topics that we’ll dive into deeply as part of this training class…
  • Speaker notes:1. While we are expanding support for 3rd party frameworks, we have lots of customers who are on MSTest and we will continue investing in it for them2. Potential rude QA, Mstest sucks because….Where is Assert.Throws?Where is DataRow support?Answer: We are fully aware that we are behind on some key features, we are not done yet and will keep working to close the gap here
  • As needed, use this as an opportunity to demonstrate work items in general. For an upgrade class, hopefully this is minimized.
  • Peter – fix the final sentence this time. 
  • Image source: http://www.sxc.hu/photo/1125087
  • Maybe retitle this?
  • BHARRY: Unit testing – One of the big problems with unit testing SharePoint is that most code requires SharePoint to be running and trying to run tests against a live SharePoint instance is a pain.  So we’ve built a SharePoint “emulator” using our new VS 2012 Fakes & Stubs capability.  This will make unit testing of SharePoint components WAY easier.Coded UI support – Our 2012 product was pretty close to supporting this but there were a few SharePoint specific issues that we weren’t able to address that made CodedUI (functional testing) not work well for SharePoint.  In our first update, we will have addressed those issues.Workarounds documented for Excel on Sharepoint 2010, Visio\\Powerpoint controls, and SharePoint Silverlight controlsLoad testing – We now support load testing for SharePoint out of the box.  This is more involved than you might imagine due to how dynamic SharePoint is.  You can’t just record a script and play it back – it won’t work because SharePoint generates and expects dynamic data (like GUIDs).  We’ve built the extensions to our load testing solution to parse the dynamic SharePoint data and include it appropriately in subsequent requests.  So now you can record a script and play it back and we will dynamically adjust it to match what SharePoint expects.IntelliTrace collection plan – While this won’t be in the first CTP, we’re building a custom IntelliTrace collection plan for SharePoint that helps filter out a bunch of the SharePoint “infrastructure noise” and lets you focus on events related to your components that are the likely cause of problems you are seeing.SOMA: SharePoint Development. Beyond the core platform support for SharePoint development available via “Napa” and the Office Developer Tools for Visual Studio, with Visual Studio 2012 Update 1 we’ve invested in building out significant new application lifecycle management (ALM) capabilities for SharePoint applications.  This work is primarily centered around multiple forms of testing: from load testing that enables the stressing of SharePoint applications with simulated load and network conditions; to performance testing that enables recording and running performance suites against SharePoint solutions; to unit testing that enables coded UI tests for simulating user interaction and that enables using the Microsoft Fakes Framework for stubbing out SharePoint dependencies in unit tests.  Update 1 also updates IntelliTrace to capture SharePoint logging information, in order to provide a rich analysis experience for SharePoint applications.
  • VS Blog:SharePoint Emulators provide a system of Fakes based shims implementing the basic behaviors of the SharePoint 2010 server object model. SharePoint Emulators are available today through a NuGet package feed. Perform a simple search of the NuGet official feed for “SharePoint Emulators”.SharePoint Emulators are easy to incorporate into existing tests. You can write tests against the SharePoint Emulators using only the SharePoint API. All that is needed is the wrapping of test code in a SharePointEmulationScope.
  • There are also things like JSLint, etc. for other platforms
  • As needed, use this as an opportunity to demonstrate work items in general. For an upgrade class, hopefully this is minimized.
  • This is the teaser for the class – we will preview (in slides) many of the topics that we’ll dive into deeply as part of this training class…
  • Source: http://blogs.msdn.com/b/visualstudioalm/archive/2012/02/29/what-s-new-for-microsoft-test-manager-in-visual-studio-11-beta.aspx?PageIndex=2#comments
  • As needed, use this as an opportunity to demonstrate work items in general. For an upgrade class, hopefully this is minimized.
  • Want to know more?
  • Want to know more?
  • Quality Coding: What’s New with Visual Studio 2012

    1. 1. Quality Coding: Whats New with VisualStudio 2012The newest release of Visual Studio 2012 is rich with new toolsthat enhance standard developer activities. In this session, wellreview and demonstrate some of these new features, such asUnit Testing, Code Reviews, Code Clones, and other developertools. Come join us for this free Webinar!
    2. 2. 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
    3. 3. Initial Project Portfolio RetireRecognizing the Iterative Nature of ApplicationsDefine•Requirements•Validation•Prioritization•Release PlanDevelop•Iteration Plan•Develop•TestOperate•Monitor•Support•UpgradePlanWorkDonePlanWorkDonePlanWorkDonePlanWorkDonePlanWorkDone
    4. 4. New ALM Capabilities in Visual Studio 2012Define•Requirements•Validation•Prioritization•Release PlanDevelop•Iteration Plan•Develop•TestOperate•Monitor•Support•Upgrade
    5. 5. Quality in Requirements: Storyboarding• Tighter loop between the BusinessStakeholders and Development Team• Graphical design tools built inPowerPoint• Embed other content includingcontext slides• Capture screen shots and createlightweight animations• Store common elements within ashape library• Create master templates to simplifymultiple similar views• Get feedback to others– Email, print and version control thedocument– leverage collaborative tools– leverage web viewing tools– Integration with TFS
    6. 6. 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
    7. 7. Why invest in quality?• Quality is an expensive (and painful) afterthought51015202530Relative CostTo Fix Bugs...Courtesy of theNational Institute of Software and Technology (NIST)
    8. 8. Problems...• It is expensive to find and fix bugs that get past dailydevelopment practices• It is hard to diagnose errors at runtime• Why does an application run slowly?• Individual Developers and Testers need to know ifthey 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?
    9. 9. 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
    10. 10. Unit Testing RunnerNew Test Runner:• Tests run in background• Run automatically on build• Support for multiple unittesting frameworks:– MS Test– xUnit– nUnit– And More!• Deep integration in theIDE• Supports native C++ code• Multiple run options– Failed Tests– Not-run Tests– All Tests• Easy code coverage access
    11. 11. public double MethodA() { ... }Unit Testing• Diagnostic checks during development– Automated test script for methods on a type– Basic sanity checking– Useful for regression testingpublic void TestMethodA(){SomeClass c = new SomeClass(); // Arrangedouble d = c.MethodA(); // ActAssert.AreEqual(expected, d); // Assert}Eachmethodhasoneormorecorrespondingtestmethods
    12. 12. 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)
    13. 13. 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!
    14. 14. Continuous Testing• “If you aren‟t running your unit tests, you are justcompiling. You are not building.”• Chris PattersonProgram ManagerTeam Foundation Build• Run Tests After Build optionin Visual Studio 2012 will runyour Unit Tests after eachsuccessful build of yoursolution
    15. 15. Code coverage in VS 2012• Analyze your codecoverage with a singleclick• Analyze for selectedtests to help find howspecific tests arecovering your system• Supports all managed &native frameworks
    16. 16. DEMONSTRATION• Unit Test Basics• Unit Test Explorer• Framework Plug-Ins• Continuous Testing• Code Coverage• Play Lists (Update 2)
    17. 17. What‟s missing?• Test Lists– Legacy mode only• Test Impact– Works on the server, not inthe VS client• Private Accessors– Deprecated in VS 2010,removed in VS 2012• Generate Unit Test– Didn‟t actually generate aunit test
    18. 18. Unit Testing and Isolation• Unit Tests verify the smallest testable „unit‟ of code• Target code should be isolated from externalinfluences• Unit Test frameworks can perform integration testingTarget Pseudo-Code:Function DoSomething(a)x = LookupInDatabase(a)y = ProcessWithWebService(x)LogToFile(“Processing complete”)End FunctionUnit Test Pseudo-Code:T = new SomeClass()result = T.DoSomething(1)Assert.AreEqual(2,result)End FunctionResponsecontrolledby testResponsecontrolled by testResponsecontrolledby test
    19. 19. What is un-testable code?Where do we find it?• “Get „er done” code– Business logic in code-behind– Classes with too manydependencies– Database logic mixed withbusiness logic• Testability was not aconsideration– Or was explicitly avoided• Monolithic, highly-coupled designsCommon 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 orwhere the tests run very slowly is unsuitable for the kind ofdeveloper testing we really care about.
    20. 20. void FileExistsTest() {File.Write("foo.txt", "");var result = IsFileEmpty("foo.txt")Assert.IsTrue(result);}File.Write("foo.txt", "");A simple test setup exampleThe method we want to unit testbool IsFileEmpty(string file) {var content = File.ReadAllText(file);return content.Length == 0;}File.ReadAllText(file);
    21. 21. Environmental DependenciesConsider the following Y2K code:public void ThrowIfEndOfTheWorld(){if (DateTime.Now == new DateTime(2000,1,1))throw new Y2KBugException();}
    22. 22. [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 DependenciesHow about this? Why is this bad?
    23. 23. Isolating code with Microsoft Fakes• Visual Studio 2012 Fakes letsyou isolate almost any .NET• Fakes come in two flavors– Stubs: concrete implementationsof interfaces or abstract classes– Shims: run-time interception letsyou replace calls, even thosefrom the .NET BCL
    24. 24. Visual Studio 2012 Shims – Be Cautious• Runtime interception of any .NETmethod– Uses the profiler to detour calls– “Monkey patching” for .NET• Use it when you…– Have external components that cannot berefactored• SharePoint, ASP.NET, Office, etc.– Need to override non-virtual methods• Static methods, constructors, sealedtypes, properties– Have legacy code with untestable designs
    25. 25. SharePoint Development Enhancements• SharePoint improvements (Update 2)– Unit test emulator– Coded UI test support– Web Performance test support– Load test support– IntelliTrace collection plan
    26. 26. SharePoint and Unit Testing[TestMethod]public void ScheduleAppointmentReturnsTrueWhenNewAppointmentIsCreated(){using (new SharePointEmulationScope(EmulationMode.Enabled)){//ArrangeSPSite site = new SPSite("http://localhost");string listName = String.Format("List{0}", Guid.NewGuid());// create a new temporary listGuid listId = site.RootWeb.Lists.Add listName, listName, SPListTemplateType.GenericList);SPList list = site.RootWeb.Lists[listId];Assert.IsNotNull(list);// add fields to listlist.Fields.Add("Name", SPFieldType.Text, true);list.Fields.Add("Date", SPFieldType.Text, false);list.Update();// preparestring errorMsg = string.Empty;DateTime date = DateTime.Now;BookAnAppointmentWebPart webPart = new BookAnAppointmentWebPart();// Actbool success = webPart.ScheduleAppointment(site.RootWeb, list.Title, "My Name","888-888-8888", "My.Name@contoso.com", "23", date, out errorMsg);// AssertAssert.IsTrue(success);// cleanuplist.Delete();site.Dispose();}}
    27. 27. Code ReviewsPurpose:– 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 teammembers– Improve overall structural quality of the code and skillset ofthe team!
    28. 28. Integrated Code Review• Providesfeedback fromother teammembers• Sharedknowledgeacross team• Code reviewscan be set as aquality gate• Source changeshighlighted andcomments aboutthe changes.
    29. 29. Automated Reviews?• Static Code Analysis:– Analyze code (MSIL/SQL) basedon 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
    30. 30. Code Clone Detection• Reviews common codeblocks exposingrefactoringopportunities• Detect code blocks withcommon structure andapproach• Search is semantic, notjust literal• Detects „copy andpaste‟ errors• Detects code fragmentswith a common logicalstructure• Review common codeand decide how toproceed
    31. 31. DEMONSTRATIONCode ReviewsCode ComparisonStatic Analysis
    32. 32. 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
    33. 33. 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
    34. 34. Web Access – Test Hub
    35. 35. Initiating Exploratory Testingor no work item.Explore based on specific workitem(s)…
    36. 36. Performing Exploratory Testing• Familiar Test Runner interface customizedfor exploratory testing• Free-form comment area allows tester torecord suggestions and problemsencountered during the session• Comment area allows for rich-text, attachments, and easy insertion ofscreenshot• Session can be paused to perform activitiesoutside of the Test Runner• Bug and Test Case work items can readilybe created during the exploratory testingsession
    37. 37. Coded UI – UI Map EditorIt‟s in the box now!
    38. 38. DEMONSTRATIONExploratory TestingCross-browserCoded UI Testing
    39. 39. Questions?
    40. 40. Want to know more...?
    41. 41. Imaginet‟s New Blog Keeps You In The Knowhttp://blog.imaginet.comStay up to speed on the latest news fromImaginet, Microsoft, Visual Studio, and the entire softwaredevelopment world.
    42. 42. 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 FirstAutomated 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 YourApplications• 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)
    43. 43. Free Services from Imaginet & MicrosoftThere are a number of different Microsoft Programs that youmight be able to leverage to get some free services fromImaginet:• Deployment Planning Services (DPS) – You can trade in yourMicrosoft Software Assurance credits to receive some freeTFS/ALM Deployment Planning Services days with Imaginet• Partner Services Credit (PSC) – Have you or are you about tospend money with Microsoft on Visual Studio 2012 products? Ifso, Microsoft may kick in some funding to help you successfullyadopt.• Virtual Technical Specialist (VTS) hours –You may be eligibleto receive some free remote consulting/training hours withImaginet through the Microsoft Virtual Technical Specialistprogram.For more information, email bmadison@imaginet.com.
    44. 44. Need Help with YOUR Automated Testing?• Learn best practices for test selection, extension, databinding, maintenance, frameworks, community extensions(such as the CUITe and the UI Map Toolbox), and otherreal-world scenarios.• Includes automated test development & execution for YOURapplication• Support and training for your team• Includes a high-level ALM assessmentImaginet’s Visual Studio 2012Automated Testing 5-day QuickstartInterested? Just email us at info@imaginet.com.
    45. 45. Email us at:ALM Planning & Implementation ServicesALM Planning• ALM Assessment & Envisioning Workshops(3 or 5 days)• VS & TFS Migration Planning Workshop (5days)• TFS Deployment Planning* (5 days)• Visual SourceSafe to TFS MigrationPlanning* (3 Days)• Visual Studio Quality Tools DeploymentPlanning* (5 days)Upgrade• TFS 2010 Adoption Quick Start (5 or 10days)• TFS 2012 Adoption Quick Start (5 or 10days)• TFS 2010 Upgrade Quick Start (10 days)• TFS 2012 Upgrade Quick Start (10 days)Remote Support• Remote Support for TFS & Visual StudioLab• Visual Studio Lab Management Quick Start(10 days)Testing• Manual Testing with Test Manager QuickStart (5 days)• Visual Studio Testing Tools Quick Start (10days)• Visual Studio Automated Testing Quick Start(5 days)• Visual Studio Load Testing Quick Start (5 or10 Days)Builds• Automated Build & Release ManagementQuick Start (5 days)• Automated Build Center of Excellence (CoE)Database• Visual Studio Database Tools Quick Start(10 days)Integrations• Team Foundation Server (TFS) & ProjectServer Integration Quick Start (10 days)• TFS & Quality Center Integration/MigrationQuick Start (10 days)
    46. 46. For questions or more information,please contact us at:info@imaginet.com or (972)607-4830Remember to add http://blog.imaginet.com to your favorite reader!
    47. 47. http://www.imaginet.com

    ×