Getting Started with Microsoft Pex and Moles

Similar documents
Environment Modeling for Automated Testing of Cloud Applications

Essential Visual Studio Team System

The best way to get Microsoft Visual Studio 2005 is by purchasing or renewing an MSDN Subscription today.

Programmabilty. Programmability in Microsoft Dynamics AX Microsoft Dynamics AX White Paper

Realistic? Content management initiatives can be a huge investment of time, money, and resources.

Measurement Studio. Contents RELEASE NOTES

Authoring for System Center 2012 Operations Manager

SharePoint Server Quick Start Guide for Single Server Farms

System Requirements for Microsoft Dynamics NAV 2013 R2

Integration test in SharePoint

Rational Quality Manager. Quick Start Tutorial

Hyper-V Server 2008 Getting Started Guide

IBM WebSphere ILOG Rules for.net

MSSQL quick start guide

ASSURING SOFTWARE QUALITY USING VISUAL STUDIO 2010

MicrosoftDynam ics GP TenantServices Installation and Adm inistration Guide

CLOUD COMPUTING & WINDOWS AZURE

Stellar Phoenix Exchange Server Backup

Introduction to Automated Testing

Microsoft Dynamics GP. Business Analyzer

> Define the different phases of K2 development, including: understand, model, build, maintain and extend

BarTender s.net SDKs

Understanding SharePoint Development Choices

AdminToys Suite. Installation & Setup Guide

Effective Team Development Using Microsoft Visual Studio Team System

Microsoft Dynamics GP Release

Planning the Installation and Installing SQL Server

How to get MOSS 2007 dev. environment set up in Vista with sample project.

Your guide to DevOps. Bring developers, IT, and the latest tools together to create a smarter, leaner, more successful coding machine

White Papers: Unit Testing. Unit Testing

Archive Attender Version 3.5

Product Overview and Architecture

Microsoft Dynamics GP SQL Server Reporting Services Guide

BUILDER 3.0 Installation Guide with Microsoft SQL Server 2005 Express Edition January 2008

Standalone Trial Guide

Agile Business Suite (AB Suite)

Transferring an Automated Test Generation Tool to Practice: From Pex to Fakes and Code Digger

Team Foundation Server 2010, Visual Studio Ultimate 2010, Team Build 2010, & Lab Management Beta 2 Installation Guide

Deploying Web Applications in Enterprise Scenarios

Developing ASP.NET MVC 4 Web Applications Course 20486A; 5 Days, Instructor-led

Unit Testing with zunit

Course 20489B: Developing Microsoft SharePoint Server 2013 Advanced Solutions OVERVIEW

What s New. Microsoft Corp. All rights reserved

Smarter Balanced Assessment Consortium. Recommendation

System Requirements for Microsoft Dynamics NAV 2016

Windows Azure Pack Installation and Initial Configuration

Environmental Modeling for Automated Cloud Application Testing

DE-20489B Developing Microsoft SharePoint Server 2013 Advanced Solutions

Developing Microsoft SharePoint Server 2013 Advanced Solutions MOC 20489

Operations Guide for the System Center Cloud Services Process Pack

Guidelines and Procedures for Project Management

Appendix F: Instructions for Downloading Microsoft Access Runtime

Download and Installation Instructions. Visual C# 2010 Help Library

SharePoint Checklist and Resources

SPT2013: Developing Solutions with. SharePoint DAYS AUDIENCE FORMAT COURSE DESCRIPTION STUDENT PREREQUISITES

Symplified I: Windows User Identity. Matthew McNew and Lex Hubbard

InRule. The Premier BRMS for the Microsoft Platform. Benefits THE POWER OF INRULE. Key Capabilities

Developing Microsoft SharePoint Server 2013 Advanced Solutions

Citrix EdgeSight Active Application Monitoring Installation Guide

Microsoft PPM for Application Administrators using Microsoft Project Online

Microsoft Dynamics NAV

Administration Guide for the System Center Cloud Services Process Pack

Part IV Patterns & Practices Security Resources

K2 Designer for SharePoint Hands-On Exercise - Leave Request process

APPENDIX A: MOCKITO UNIT TESTING TUTORIAL

Developing Solutions for Microsoft Dynamics AX in a Shared AOS Development Environment

Implementing and Maintaining Microsoft SQL Server 2008 Integration Services

Microsoft Dynamics GP econnect Installation and Administration Guide

Course Outline: Course 20489B: Developing Microsoft SharePoint Server 2013 Advanced Solutions

Gallio: Crafting a Toolchain. Jeff Brown jeff.brown@gmail.com

Getting Microsoft Outlook and Salesforce in Sync

Developing ASP.NET MVC 4 Web Applications

DigitalPersona, Inc. Altus AUTH SDK. Version 1.1. Developer Guide

V2.8.x Installation on a Database Server Note: This document is to be used on a new database server installation.

AB Suite in the Application Lifecycle

Integrated Virtual Debugger for Visual Studio Developer s Guide VMware Workstation 8.0

Configuring budget planning for Microsoft Dynamics AX 2012 R2

Offline Database Development and Unit Testing with SSDT. Andrey Zavadskiy

Business Portal for Microsoft Dynamics GP Field Service Suite

Sage Estimating (SQL) (formerly Sage Timberline Estimating) Release Notes. Version (Controlled Release)

Business Portal for Microsoft Dynamics GP Project Time and Expense Administrator s Guide

SQL Server 2005: Report Builder

How to test and debug an ASP.NET application

Dynamics AX. Microsoft Dynamics AX 4.0. Microsoft Dynamics ISV Software Solution Test Guidelines

Hypercosm. Studio.

2.0. Quick Start Guide

Parallels Transporter Agent

Metalogix Replicator. Quick Start Guide. Publication Date: May 14, 2015

Sage 100 ERP. Installation and System Administrator s Guide

Windows BitLocker Drive Encryption Step-by-Step Guide

Team Foundation Server 2013 Installation Guide

Getting Started with the Ed-Fi ODS and Ed-Fi ODS API

Python for Series 60 Platform

Getting Started Guide

Sharpdesk V3.5. Push Installation Guide for system administrator Version

Acronis Backup & Recovery 10 Server for Windows. Workstation. Quick Start Guide

Microsoft Corporation. Project Server 2010 Installation Guide

Key Benefits of Microsoft Visual Studio Team System

Last edited on 7/30/07. Copyright Syncfusion., Inc

Describe how to utilize the Publishing API to access publishing settings and content.

Transcription:

Getting Started with Microsoft Pex and Moles Automated Whitebox Testing for.net Framework Applications A few clicks to better, easier testing for.net code Microsoft Moles 2010 is a Microsoft Visual Studio 2010 add-in that helps you to isolate.net Framework code from external dependencies, in order to test reliably whether the code performs as intended. With the Moles framework, you can replace any method that the code-under-test calls with a test implementation that uses a delegate. Microsoft Pex 2010 is a Visual Studio add-in that provides runtime code analysis for.net code. With just a few mouse clicks, you can: Explore code-under-test to understand input/output behavior in the code. Save automated tests that increase your confidence that your code cannot crash or point to errors that do cause crashes. Write powerful parameterized unit tests and generate suites of tests that ensure the code-under-test behaves as intended. This guide briefly describes the requirements and installations steps for Microsoft Pex and Moles. The rest of this guide explains why you want to use Pex and Moles in your testing practices and how to get started. Note: Most resources discussed in this paper are provided with the Pex and Moles software packages. For a complete list of documents and references discussed, see Resources and References at the end of this document. For up-to-date documentation, Pex and Moles news, and online community, see http://research.microsoft.com/pex

Getting Started with Microsoft Pex and Moles - 2 Contents Installation and Configuration for Microsoft Pex and Moles... 3 Introduction to Microsoft Pex and Moles... 4 Microsoft Moles 2010... 4 Microsoft Pex 2010... 4 Learning to Use Pex and Moles... 5 Resources and References... 7 Disclaimer: This document is provided as-is. Information and views expressed in this document, including URL and other Internet Web site references, may change without notice. You bear the risk of using it. This document does not provide you with any legal rights to any intellectual property in any Microsoft product. You may copy and use this document for your internal, reference purposes. Microsoft, Visual Studio, Windows Server, Windows Vista, and Windows are trademarks of the Microsoft group of companies. All other trademarks are property of their respective owners.

Getting Started with Microsoft Pex and Moles - 3 Installation and Configuration for Microsoft Pex and Moles Prerequisites To use Microsoft Pex and Moles in your testing lifecycle, you should be familiar with the following: Microsoft Visual Studio 2010 C# programming language.net Framework Version 2.0 or later Basic practices for building, debugging, and testing software Computer Configuration The software and accompanying tutorials require that the following software components are installed on your testing or development system: Windows 7, Windows Vista, or Windows Server 2008 R2 or later operating system Visual Studio 2010 Professional Microsoft Pex and Moles also work with Visual Studio 2008 Professional; this tutorial assumes that your edition supports the Visual Studio Unit Testing framework. Microsoft Pex 2010 and Microsoft Moles 2010 Note: The Moles framework can be installed and used as a standalone tool. It is also included in the Pex software package. To install Pex and Moles 1. Download Moles and Pex to start installation. 2. As with all Windows software, accept the prompt to run the software. 3. Click Next on the Setup Wizard Welcome page, and accept the license agreement to proceed. 4. Choose Setup Type Typical, Custom, or Complete and then click Install. If you choose complete Pex and Moles package, make sure you have 100 MB of free disk space. Tip: At the end of setup, check the Getting Started box for an overview of what Pex is all about. Getting Help For questions, see Resources and References at the end of this document. If you have a question while using Pex and Moles, post it on the Pex and Moles forum.

Getting Started with Microsoft Pex and Moles - 4 Introduction to Microsoft Pex and Moles Microsoft Pex and the Moles framework can make unit testing of.net Framework applications more effective and can help you to overcome oftenencountered difficulties. With the help of Pex and Moles, you can prioritize unit testing in your test strategy and reap the benefits of greater defect detection in your development cycle. Microsoft Moles 2010 Microsoft Moles is a lightweight mocking framework for test stubs and detours, which provides a means for stubbing static properties and methods. The Moles framework allows replacing any.net method with a delegate. In the context of unit testing, you can use Moles to isolate from environment dependencies such as time, file system, database, and so on, even when those dependencies are hard-coded through static method or sealed types. For example, it is difficult to create unit tests for Microsoft SharePoint Foundation applications, because you cannot execute the functions of the underlying SharePoint Object Model without being connected to a live SharePoint Server. You can use the Moles framework to detour calls to the SharePoint Object Model. These detours can be used later on to bypass the SharePoint Object Model and fake its behavior. With Moles, you can detour any.net method to user-defined delegates. Moles can be used to isolate any.net application. Microsoft Moles can run as a standalone tool. After installation, you can directly access the Moles API Reference, Samples, and documentation from the Windows Start menu. Microsoft Pex 2010 Microsoft Moles helps with writing unit tests, but what remains is the tedious task of writing the specific unit tests that exhaustively exercise and validate the logic of the code-under-test. Microsoft Pex can help you in understanding the input/output behavior of your code, finding inputs that cause the code-undertest to crash, and exploring parameterized unit tests to check whether your code implements the desired functionality for all inputs. When you run Microsoft Pex on your.net code, Pex generates test cases by analyzing the code-under-test. For every statement in the code, Pex will eventually try to create a test input that will reach that statement. Pex will do a case analysis for every conditional branch in the code for example, if statements, assertions, and all operations that can throw exceptions. The result appears as a table that shows each test attempted by Pex. Each line in the table shows the input and the resulting output or exceptions generated by the method for the specific input.

Getting Started with Microsoft Pex and Moles - 5 Pex enables parameterized unit testing, an extension of unit testing that reduces test maintenance costs: Pex can generate inputs for manually written parameterized unit tests by analyzing the branch conditions in the code-under-test. Pex tries to find bugs in existing.net assemblies by using the Pex Wizard to create simple parameterized unit tests automatically. Pex uses a constraint solver to systematically generate relevant inputs for the code-under-test. The result is a minimal test suite with maximum code coverage. Pex creates tests and mocks for MSTest. When a generated test fails, Pex often suggests a bug fix based on the Pex systematic program analysis. Learning to Use Pex and Moles Microsoft Pex and Moles software package includes tutorials that introduce basic steps to help you to create your first project. Microsoft Moles Tutorials. To help you get started, we recommend that you review these tutorials: 1. Unit Testing with Microsoft Moles (Level 200) A step-by-step introduction to using the Moles framework to replace a.net method with your own delegate when testing. The Moles framework supports interfaces, abstract classes, sealed types, static classes, and methods. 2. Unit Testing SharePoint Foundation with Microsoft Pex and Moles (Level 300) A brief, step-by-step guide to writing isolated unit tests for applications that use Microsoft SharePoint Services.

Getting Started with Microsoft Pex and Moles - 6 As you begin to use the Moles Framework, use Microsoft Moles Reference Manual as a handy reference with details to help you extend testing strategies that require isolating test cases from environment dependencies. Microsoft Pex Tutorials. We recommend that you review these tutorials: 1. Exploring Code with Microsoft Pex (Level 200) A step-by-step guide to using Pex to understand the behavior of.net code, identify potential issues, and automatically create a test suite. 2. Parameterized Unit Testing with Microsoft Pex (Level 400) A set of exercises to demonstrate the principles of Parameterized Unit Testing in Visual Studio with Pex, with key aspects for making the methodology successful in practice. After you have practiced with the basics, you ll find these references and advanced documents useful: Parameterized Test Patterns for Microsoft Pex (Level 400) Common patterns for parameterized unit tests, written with automatic test input generation tools such as Pex in mind. Advanced Concepts: Parameterized Unit Testing with Microsoft Pex (Level 500) A comprehensive looks at whitebox software testing, with a detailed explanation of how Pex works. Microsoft Pex Reference Manual (Level 400) A comprehensive reference, with details on settings, warnings and errors, exit codes, and static helper classes. A guide to technical levels for documentation Level Example 100 Overview 200 Basic Guide 300 Specific Solutions 400 Expert Content An introduction to goals for Microsoft Pex and Moles, plus steps for installation. Step-by-step details for running the software, with implementation information for general problems. Deeper code samples to solve specific problem situations. Assumes you understand basic concepts and are familiar with the software so that you are ready to study real-world solutions. A deep collection of technical knowledge, intended for developers with extensive experience, focusing on expert-to-expert information and coverage of specialized topics.

Getting Started with Microsoft Pex and Moles - 7 See How Pex and Moles Can Help To begin to think about how Microsoft Pex can contribute to your testing practices: If you want to... Test an existing code base Write parameterized unit tests Isolate your code from environment dependencies You can... Use Pex in Visual Studio see Exercise 1 in Exploring Code with Microsoft Pex. Write your own parameterized unit tests, or simply use the Pex Wizard to generate a set of parameterized unit test templates and parameterized mocks see the exercises in Parameterized Unit Testing with Microsoft Pex. Use Moles to isolate your code as introduced in Unit Testing with Microsoft Moles. Then learn to use Pex and Moles together, with Pex exploring your unit tests. This capability is shown extensively in Unit Testing SharePoint Foundation with Microsoft Pex and Moles Begin Writing Parameterized Unit Tests A parameterized unit test is simply a method that takes parameters, calls the code under test, and states assertions. Parameterization allows you to separate two concerns: The specification of the behavior of the system. The test cases to cover a particular implementation. Parameterized unit tests can be written before the first line of the implementation code, or they can be added at a later point in time. Once both are written and compiled, Pex can explore parameterized unit tests in combination with the code-under-test. Resources and References Pex Resources, Publications, and Channel 9 Videos Pex and Moles at Microsoft Research http://research.microsoft.com/pex/ Pex Documentation Site Pex and Moles Tutorials Technical Level: Getting Started with Microsoft Pex and Moles 200 Getting Started with Microsoft Code Contracts and Pex 200 Unit Testing with Microsoft Moles 200 Exploring Code with Microsoft Pex 200 Unit Testing Asp.NET applications with Microsoft Pex and Moles 300 Unit Testing SharePoint Foundation with Microsoft Pex and Moles 300 Unit Testing SharePoint Foundation with Microsoft Pex and Moles (II) 300 Parameterized Unit Testing with Microsoft Pex 400

Getting Started with Microsoft Pex and Moles - 8 Pex and Moles Technical References Microsoft Moles Reference Manual 400 Microsoft Pex Reference Manual 400 Microsoft Pex Online Documentation 400 Parameterized Test Patterns for Microsoft Pex 400 Advanced Concepts: Parameterized Unit Testing with Microsoft Pex 500 Community Pex Forum on MSDN DevLabs Pex Community Resources Nikolai Tillmann s Blog on MSDN Peli de Halleux s Blog Terminology code coverage Code coverage data is used to determine how effectively your tests exercise the code in your application. This data helps you to identify sections of code not covered, sections partially covered, and sections where you have complete coverage. With this information, you can add to or change your test suites to maximize their effectiveness. Visual Studio Team System helps measure code coverage. Microsoft Pex internally measures coverage knowledge of specific methods under test (called dynamic coverage ). Pex generates test cases that often achieve high code coverage. delegate A delegate is a reference type that can be used to encapsulate a named or an anonymous method. Delegates are similar to function pointers in C++; however, delegates are type-safe and secure. For applications of delegates, see Delegates in the C# Programming Library on MSDN. explorations Pex runs the code-under-test, using different test inputs and exploring code execution paths encountered during successive runs. Pex aims to execute every branch in the code-under-test, and will eventually execute all paths in the code. This phase of Pex execution is referred to as Pex explorations. integration test An integration test exercises multiple test units at one time, working together. Integration tests exercise a target system such as a database, file system, or SharePoint. In an extreme case, an integration test tests the entire system as a whole. mock A mock is an object that provides limited simulation of another object for testing a specific scenario. For example, a mock can be created that returns specific error codes that might take too long to occur naturally.

Getting Started with Microsoft Pex and Moles - 9 mole type The Moles framework provides strongly typed wrappers that allow you to redirect any.net method to a user defined delegate. These wrappers are called mole types, after the framework that generates them. A method that has been wrapped like this is referred to as moled. stub type Usually a stub type is a trivial implementation of an object that does nothing. In the Moles framework, it is specifically a type generated for interfaces and non-sealed classes, which allows you to redefine the behavior of methods by attaching delegates. unit test A unit test takes the smallest piece of testable software in the application, isolates it from the remainder of the code, and determines whether it behaves exactly as you expect. Each unit is tested separately. Units are then integrated into modules to test the interfaces between modules. The most common approach to unit testing requires drivers and stubs to be written, which is simplified when using the Moles framework. whitebox testing Whitebox testing assumes that the tester can look at the code for the application block and create test cases that look for any potential failure scenarios. During whitebox testing, you analyze the code of the application block and prepare test cases for testing the functionality to ensure that the class is behaving in accordance with the specifications and testing for robustness.