© 2012 Autodesk Automated Testing with the AutoCAD ®.NET API Scott McFarlane Senior Software Engineer, Woolpert, Inc.

Slides:



Advertisements
Similar presentations
Construction Documents and Details
Advertisements

© 2011 Autodesk Go Big or Go Home! Part 1 – Large Scale Autodesk Vault Deployments Irvin Hayes Jr. Technical Product Manager.
© 2011 Autodesk Capitalize on Corridor Improvements in AutoCAD ® Civil 3D ® Don Quinn Civil Engineer / Eagle Point Product Specialist.
© 2012 Autodesk “Clash of The Design Teams” using Autodesk BIM 360 Glue & Revit Jason Jones Jason Waddell PES Structural Engineers The Beck Group BIM Program.
© 2012 Autodesk How to Establish Autodesk® PLM 360 as the Platform for Enabling PLM and Related Processes Prayush Saraswat PLM Business Process Consultant.
© 2011 Autodesk Navigating Through the Corridor using AutoCAD® Civil 3D®.NET API Augusto Goncalves Senior Developer Consultant at Autodesk.
Lecture 6 Software Testing and jUnit CS140 Dick Steflik.
© 2012 Autodesk Using Autodesk ® Inventor ® for Sales Mark Keenan Business Development, Technicon Systems, Inc.
© 2012 Autodesk CM6070-V Extend Revit Server with IMAGINiT Clarity Beau Turner Product Director.
© 2012 Autodesk Conceptual and Design Workflows Using Autodesk ® 360 Integrated Applications Anirban Ghosh Principal User Experience Designer – DLS Mobile.
© 2011 Autodesk Single Job 1 Processor 1 Single Job 2 Single Job 3 Processor 2 Processor 3 Big Job 1 Big Job 2 Single Job 4 Processor 1 Single Job 5 Single.
© 2011 Autodesk Mechatronics-Taming the Beast Randy Brunette Consultant, Trainer, All Around Good Guy Brunette Technologies, LLC.
© 2012 Autodesk Dario Nicolini Product Manager Autodesk ® Inventor ® iLogic: a great Autodesk tool to improve Inventor features.
SWE 316: Software Design and Architecture – Dr. Khalid Aljasser Objectives Lecture 11 : Frameworks SWE 316: Software Design and Architecture  To understand.
© 2013 Autodesk Autodesk ® ReCap ™. © 2013 Autodesk What is Reality Capture? Reality capture is the process of taking the analog world around us and putting.
Scripting Components for AutoCAD Plant 3D
© 2012 Autodesk Do More With Less ETO API’s Ishwar Nagwani Technical Consultant.
© 2011 Autodesk CP5239 Demand-Loading AutoCAD®.NET Plug-ins James E. Johnson Synergis Software Sr. CAD Developer.
Test Driven Development Arrange, Act, Assert… Awesome Jason Offutt Software Engineer Central Christian Church
© 2012 Autodesk AutoCAD ® Virtualized and Digitized michael trachtenberg - AE BackOffice Software Director.
© 2012 Autodesk The Devil Is In The Workflow Module 1: Successfully Plan and Implement BIM Luis Rojas Building Design Product Line Manager, Eagle Point.
Customizing Autodesk® Navisworks® 2013 with the .NET API
© 2012 Autodesk Effective Collaboration Techniques for the Architect & Construction Engineer Using Copy Monitor in Autodesk Revit Jason Jones PES Structural.
© 2011 Autodesk CM D Standards : New Thinking Allan Chalmers – Kempe Engineering Kevin J. Smedley – Engineering Design Systems, Inc.
© 2012 Autodesk Project Architect-Times-a-Changing: How to transition from yesterday to today Christopher Ozog Project Architect.
© 2012 Autodesk Dirty Laundry: Cleaning Up Your Sheets with AutoCAD® Sheet Set Manager Tim Douglas Boise Sales Manager at ProSoft.
© 2012 Autodesk AutoCAD on Electrical Steroids Randy Brunette Electrical Subject Matter Expert (Autodesk)
© 2012 Autodesk LF BIM in Manufacturing Crossing the Wall Between Product and Building Workflows Tim Bourdois Aluminum Curtainwall Systems / Netwise.
© 2012 Autodesk How to Get the Most from Integrated Project Delivery (IPD) David J. Patera Team Project Manager & VDC Coordinator.
© 2012 Autodesk PL2731 Get the foundations right before you start building Adam Peter Customer Success Engineer - Autodesk.
© 2012 Autodesk Autodesk Structural Curriculum 2013 Unit 5: Advanced Structural Analysis & Coordination Advanced Structural Analysis & Coordination.
© 2011 Autodesk Converting Existing Piping Specs Ian Matthew Technical Marketing Manager, Autodesk.
© 2011 Autodesk Popular Design Patterns and How to Implement Them in.NET Gopinath Taget Senior Developer Consultant.
© 2012 Autodesk MP2005 Autodesk Revit Architecture Room Data and AutoCAD MEP: You Did What with the Xdata? Jeff Campbell Senior Applications Specialist,
JUnit Don Braffitt Updated: 10-Jun-2011.
© 2011 Autodesk SE4247 – Modelling for Construction Ralph Pullinger Structural Technical Specialist, Autodesk, AEC Division (Northern Europe)
© 2012 Autodesk AutoCAD® API.NET Tips and Tricks James E. Johnson Application Developer for Synergis Software.
© 2012 Autodesk From Nothing to Something using AutoCAD ® Electrical Todd Schmoock Solutions Engineer - Synergis Technologies, Inc.
© 2012 Autodesk Adding Instrumentation and Electrical Capabilities to Autodesk® Plant Design Suite Andy Bonfield.
© 2012 Autodesk Can You Afford to Use Old Training Methods on New Technology? Module 1: Why Old Training Methods Don’t Work Steve Biver Civil Product Line.
Join us on Twitter: #AU2014. Class summary text goes here Class summary.
© 2011 Autodesk Optimizing Digital Drawing Files and BIM Models for Measurement and Estimating Simon Lovegrove MRICS, AAIQS Director, Exactal.
Test Driven Development Introduction Issued date: 8/29/2007 Author: Nguyen Phuc Hai.
© 2012 Autodesk Customizing AutoCAD P&ID David Wolfe Process and Power Specialist.
© 2012 Autodesk AB1851 Optimizing the Design Development Stage using Revit Architecture Douglas Bowers, AIA, LEED AP BD+C Doug Bowers Consulting, LLC.
© 2011 Autodesk AC2182 P - Autodesk 3ds Max for Starters Create Stunning Renderings For All Situations Christopher Fernandez Senior Applications Specialist,
© 2012 Autodesk The Picture Says It All: Commercial Site Plan 3D Visualizations Using Autodesk® IDS John Sayre Civil Application Engineer.
© 2011 Autodesk The Suite Life of AutoCAD® Guillermo Melantoni Sr Product Manager: Workflows and Interoperability at Autodesk.
© 2012 Autodesk SM3595-R | Thinking of Design, Engineering, and Simulation Differently! Luke Mihelcic Product Marketing Manager | ISM – Simulation Industry.
© 2012 Autodesk Collaboration Systems – It’s good to share Martin Duke Business Systems Manager.
Northwest Arkansas.Net User Group Jay Smith Tyson Foods, Inc. Unit Testing nUnit, nUnitAsp, nUnitForms.
© 2011 Autodesk Publish Autodesk® Inventor® Building Components for Consumption in AutoCAD® MEP and Revit® MEP Jay Ayala Solutions Engineer.
© 2012 Autodesk From CAD to Awesome: AutoCAD® and Autodesk® SketchBook® Designer Guillermo Melantoni Product Line Manager: Personal Design & Fabrication.
Unit Testing - solid fundamentals
Unit testing your metro style apps built using XAML
Managing the Construction Administration Phase in Autodesk® Revit®
Are You STILL Not Using AutoCAD® Civil 3D ®?
AB2623-Triage for Your Autodesk Revit Family
Water! Water! Quenching Your Thirst for Water in AutoCAD® Civil 3D®
History, Characteristics and Frameworks
Check Out These ‘Suite’ Workflows
Using Scripts, AutoLISP® and
Using Quantity Takeoff and Linked Models in Revit to Estimate a Project as the Design Changes Kevin R. Miller, Brigham Young University Scott Davis & TJ.
CM1847 Migrating AutoCAD Standards to Revit
Are Your Buildings Floating in the Air
Autodesk Navisworks: Practical Tips and Tricks from Seven Years in the Construction Industry Josh Lowe Project Lead, TURIS Systems.
BIM for Interiors: Making Autodesk® Revit® Work for You
MP1483 Massing and using Architecture Models for Revit MEP 2013 Analysis Simon Whitbread Application Specialist.
Using Quantity Takeoff and Linked Models in Revit to Estimate a Project as the Design Changes Kevin R. Miller, Brigham Young University Scott Davis & TJ.
Beyond Massing: Conceptual Design in Autodesk® Revit® Architecture 2012 David Fano Partner | CASE Design, Inc |
Presentation transcript:

© 2012 Autodesk Automated Testing with the AutoCAD ®.NET API Scott McFarlane Senior Software Engineer, Woolpert, Inc.

© 2012 Autodesk Class Summary Automated testing, which includes unit testing and integration testing, is one of the cornerstones of the Agile development process. Yet we see it as difficult and expensive, especially for programs written with the AutoCAD.NET API. So what makes it so difficult? What are the obstacles? Can we overcome them? This class will explore the topic of automated testing, specifically for.NET programs written for products based on AutoCAD software. You will learn how good programming practices, such as single responsibility, abstraction, interface development, and dependency inversion, go hand in hand with writing testable code, and how to use these techniques to decouple your code from the AutoCAD API, enabling you to unit test your business logic in Microsoft® Visual Studio®. We’ll also look at a few of the popular testing tools, including the Gallio Automation Platform, which integrates AutoCAD into its test runner.

© 2012 Autodesk Learning Objectives At the end of this class, you will be able to:  Recognize the obstacles to doing software testing, particularly with programs written for AutoCAD  Understand the goals, philosophy and principles of test automation  Appreciate the benefits of test automation  Use the correct Terminology: What is a mock, a stub, a fake, a dummy?  Use abstraction and dependency inversion to write testable code

© 2012 Autodesk Automated Testing

© 2012 Autodesk Why Am I Not Doing Automated Testing?  My programs always work correctly  I never need to modify or refactor my code  I enjoy spending hours tracking down bugs  I haven’t yet realized the benefits  I haven’t learned to do it well

© 2012 Autodesk Code-Driven Testing Frameworks  The growing family of code-driven testing frameworks have come to be known collectively as xUnit  Based on a design by Kent Beck, originally implemented for Smalltalk as SUnit, then ported to Java as JUnit.  Wikipedia lists over 360 testing frameworks for over 70 different languages and environments.

© 2012 Autodesk Basic xUnit Architecture  Test Case  Also called Testcase Class  Implemented as an interface, abstract base class, or class attribute  Contains one or more Test Methods  Typically shares the same Test Fixture  Test Method  Contains the logic for each test

© 2012 Autodesk Basic xUnit Architecture  Test Suite  A set of tests that share the same Test Fixture  SUT (System Under Test)  The actual class/method we are testing  Test Fixture  All the things we need to have in place to run a test  4-Step Test Execution  1. Setup  2. Exercise  3. Verify  4. Teardown

© 2012 Autodesk Topics  The Goals of Test Automation  Philosophy and Principles of Test Automation  Terminology: What is a mock, a stub, a fake, a dummy?

© 2012 Autodesk

Goals of Test Automation  Tests should help us improve quality  Tests should help us understand the system under test (SUT)  Tests should reduce (and -not introduce) risk  Tests should be easy to run  Tests should be easy to write and maintain  Tests should require minimal maintenance as the system evolves around them

© 2012 Autodesk Tests Should Help Us Improve Quality  What is Quality?  1. Is the software built correctly?  2. Have we built the correct software?  Tests act as an executable specification  Tests help prevent bugs  Tests help localize bugs  But… Quality is not just testing “Trying to improve the quality of software by doing more testing is like trying to lose weight by weighing yourself more often.” - Steve McConnell

© 2012 Autodesk Tests Should Help Us Understand the SUT  Rather than pouring over the code to answer:  What is this code supposed to do?  What would the result be if... ?  Tests should show the test reader how the code is supposed to work.  Tests are less likely to become out-of-sync with code than documentation

© 2012 Autodesk Tests Should Reduce (Not Introduce) Risk  Tests provide a safety net for incremental development and refactoring  Without tests, we are reluctant to make changes or try different approaches – risk is too high.  Writing good tests is not easy – It takes lots of practice  Keep tests simple, clean, easy to read  Don’t be afraid to use Test Utility Methods.  Dangers (Risks) of Automated Testing  Putting test logic in production code  Testing too many things at once  Testing too little

© 2012 Autodesk Tests Should Be Easy to Run  Tests must be…  Fully automated  Self-checking  Independent  Repeatable  Fast

© 2012 Autodesk Tests Should Require Minimal Maintenance as the System Evolves Around Them  Test only public interfaces and outcomes when possible  Avoid testing private methods directly (implementation details)  Use Mocks only when necessary  Minimize duplicate code in tests  Tests should facilitate (not hinder) our ability to make changes to the production code.

© 2012 Autodesk Summary of Goals  Trustworthiness  Are you able to run your test and trust the results?  Maintainability  Treat your test code with the same care as your production code.  Readability  Can you look at a test and quickly understand what is being tested and why it failed?

© 2012 Autodesk Testing Philosophy  Test first versus test after  Test-by-test versus test all-at-once  Outside-in versus inside-out  Behavior verification versus state verification

© 2012 Autodesk Definitions (Meszaros)  Test Double – Any object that is used in place of a real object for the purposes of testing. Mocks, stubs, fakes and dummies are all test doubles.  Mock – an object that can monitor the indirect outputs (behavior) of the SUT. Your tests assert against the mock object (rather than the SUT itself) to see if it has passed.  Stub – an object that can control indirect inputs into the SUT. A test can use multiple subs, but can only have one mock object.  Fake – an object used by the SUT that behaves exactly like the real object, but may be used to isolate the SUT from external resources. An in-memory database is an example of a Test Double.  Dummy – an object that is required by the SUT to run, but plays no active role in the test.

© 2012 Autodesk Behavior Verification vs. State Verification  Behavior Verification  State Verification Class under test Mock Test Communicate Assert Class under test Stub Test Communicate Assert Dependent Component

© 2012 Autodesk Unit Tests vs. Integration Tests Unit Tests  Should run w/o config  Isolated  No teardown required  Run in memory  Fast  Repeatable  Run often Integration Tests  May require config  Use external resources  May require teardown  May use disk or database  Slow  May not be repeatable  Run less often

© 2012 Autodesk Unit Tests vs. Integration Tests  Do not mix - Keep in separate projects/assemblies

© 2012 Autodesk Unit Testing “Thorns”  MessageBox.Show()  Timer  WebClient  System.IO (File, etc.)  DateTime.Now  Singletons/Statics

© 2012 Autodesk Testing Tools  Testing Framework (xUnit)  MSTest  NUnit  MbUnit/Gallio  Isolation Framework  NSubstitute  Moq  FakeItEasy  Other  Fluent Assertions  NCrunch

© 2012 Autodesk Obstacles to Testing AutoCAD Code

© 2012 Autodesk Obstacles to Testing AutoCAD Code  Our programs are hosted by AutoCAD  Heavy user interaction  Tightly coupled with AutoCAD API

© 2012 Autodesk Example

© 2012 Autodesk Abstraction and Dependency Injection

© 2012 Autodesk Why is Abstraction Important?  The Problem  Classes often contain dependencies on other classes to do their work.  If a class makes assumptions about how its dependent classes are implemented, the class becomes difficult to reuse in combination with other components.  Such classes are also very difficult to unit test because they cannot be isolated from their dependencies.

© 2012 Autodesk Why is Abstraction Important?  The Solution  Establish a common set of protocols by which classes interact, separately from the classes themselves.  Promotes the use of software design patterns (particularly dependency injection) that result in code that is more testable, extensible, maintainable, scalable, and reusable.

© 2012 Autodesk Typical Application Business Logic Logger FILE User Interface Exception Handler Data Access Web Service Client Component Configuration

© 2012 Autodesk Business Logic User Interface Logger FILE Exception Handler Data Access Web Service Client Component Configuration IDataRepository ILogger IMessageBox IProgressBar IExceptionHandler ISomeWebService Interface IConfiguration IHostApplication Host Application Typical Application

© 2012 Autodesk Business Logic Test Double IDataRepository ILogger IMessageBox IProgressBar IExceptionHandler ISomeWebService Interface IConfiguration Test Double IHostApplication Typical Application

© 2012 Autodesk Example 1 public class Example1 { public void DoTheWork() { DataRepository dataRepository = new DataRepository(); Logger logger = new Logger(); logger.Log("Getting the data"); DataSet theData = dataRepository.GetSomeData(); // Do some work with the data... logger.Log("Done."); }

© 2012 Autodesk Example 2 public class Example2 { private readonly IDataRepository _dataRepository; private readonly ILogger _logger; public Example2(IDataRepository dataRepository, ILogger logger) { _dataRepository = dataRepository; _logger = logger; } public void DoTheWork() { _logger.Log("Getting the data"); DataSet theData = _dataRepository.GetSomeData(); // Do some work with the data... _logger.Log("Done."); }

© 2012 Autodesk Software Engineering Principles  Separation of Concerns – This class is now only responsible for the specific job it was designed to do.  Abstraction – By using interfaces, we have established a set of protocols by which the components interact, separately from the classes themselves.  Inversion of Control – The class has relinquished control of the creation and initialization of its dependencies.  Dependency Injection – This pattern is based on Inversion of Control, and describes the way in which an object obtains references to its dependencies.

© 2012 Autodesk Application Architecture AutoCAD Main Plug-in Code (Bootstrapper) AutoCAD Specific Logic Business Logic AcDbMgd.dll AcCoreMgd.dll AcMgd.dll Shared Abstractions User Interface Other Dependencies Logging Configuration Databases Web Services Etc… Depends on AutoCAD API No dependency on AutoCAD API Interfaces Domain Objects Implements AcCoreConsole.exe Implements Unit Tests

© 2012 Autodesk Example

© 2012 Autodesk Autodesk, AutoCAD* [*if/when mentioned in the pertinent material, followed by an alphabetical list of all other trademarks mentioned in the material] are registered trademarks or trademarks of Autodesk, Inc., and/or its subsidiaries and/or affiliates in the USA and/or other countries. All other brand names, product names, or trademarks belong to their respective holders. Autodesk reserves the right to alter product and services offerings, and specifications and pricing at any time without notice, and is not responsible for typographical or graphical errors that may appear in this document. © 2012 Autodesk, Inc. All rights reserved.