Chapter 5. Testing Applications Using Visual Studio 2013

In this chapter, we will cover the following recipes:

  • Understanding Visual Studio unit test projects
  • Working with the Microsoft Fakes framework in Visual Studio
  • Understanding how Coded UI testing works in Visual Studio

Introduction

Testing is one of the most important parts of any development process cycle. Starting from the classic Waterfall Software Development Life Cycle (SDLC) model to the modern Agile-based SDLC, testing forms one of the most important sections of any development process. After the development phase is complete, the application is sent for testing. Every application, irrespective of its volume or size, is thoroughly tested before it is released for production. Testing software is so important that no software can ever be successful without going through this phase. Large enterprises keep separate teams that dedicatedly test applications and frameworks before finalizing the release. The purpose of these testing teams is to find out hidden flaws/bugs in the software, which might have been produced because of some wrong or illegal input that has not been taken care of by the developers during the phase of development. Most of these bugs come from the validation of code blocks or even logical bugs. The main motive of the testing team is to produce test cases and a bug report, which is then sent back to the development team for rectification.

As we already know, Team Foundation Server (TFS) supports a number of critical and important features, which makes communication between the development and testing teams easy and quicker than ever before using Visual Studio 2013.

When we talk about testing, the most important and common form of testing that comes to mind is unit testing. Unit testing is a method by which the developers test their source code by factoring the smallest portion of the program called units, which can be individually tested, and calling these units from outside using various logical test cases or a range of values. This method finally asserts the expected output with the actual output from the program. In most cases, unit tests are written by the White Box testers during the development process.

Note

White Box testing is done by testing the internal structure and working of an application.

Visual Studio 2013 comes with lot of advanced tools and techniques that can be used from inside the IDE to help developers easily write and run test cases on the code that they have been working on. Some of the interesting tools include:

  • Test Explorer: This lists all the unit tests that can be run from inside the IDE with logical grouping of tests based on the status of the test case. Test Explorer can also include third-party frameworks that have an adapter for the Test Explorer.
  • Microsoft Unit Test Framework: This is a general purpose test framework that is installed with the Visual Studio IDE to write unit tests.
  • Code Coverage Tools: This tool helps to find the amount of code that the unit test covers from a single command in the Test Explorer.
  • Microsoft Fakes Isolation Framework: This allows you to create classes and methods that can generate fake dependencies between various modules of the code that are in the testing phase.

    Note

    It is worth noting that unit testing is a part of Visual Studio Test Framework defined inside the Microsoft.VisualStudio.QualityTools.UnitTestingFramework.dll assembly, which is not a part of the .NET framework but a part of the Visual Studio IDE. You can work with the unit testing capabilities of Visual Studio using any version of Visual Studio except the Express edition.

In this chapter, we are going to cover some of the interesting and useful ways to define tests for our code.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.143.235.23