|
|
Want to know more about Packt's Article Network? Interested in contributing your article ideas? Please visit our FAQ for more information. See More BROWSE
All Titles WordPress Web Services SOA BPEL Web Graphics & Video Web Development RAW Portugues, Espanol, Italiano PHP/MySQL Oracle Open Source Networking & Telephony Moodle Microsoft & .NET Linux Servers Joomla! JBoss Java e-Commerce Drupal CRM Content Management Beginner Guides Architecture and Analysis AJAX Future Titles Recently Published Titles |
Visual Studio 2008 Test Types
Software testing in Visual Studio Team System 2008Before going into the details of the actual testing using Visual Studio 2008, we need to understand the different tools provided by Visual Studio Team System (VSTS) and their usage. Once we understand the tools usage, then we should be able to perform different types of testing using VSTS. As we go along creating a number of different tests, we will encounter difficulty in managing the test similar to the code and its different versions during application development. There are different features such as the Test List Editor and Test View and the Team Foundation Server (TFS) for managing and maintaining all the tests created using VSTS. Using this Test List Editor, we can group similar tests, create number of lists, add, or delete tests from the list. The other aspect of this article is to see the different file types getting created in Visual Studio during testing. Most of these files are in XML format, which get created automatically whenever the corresponding test is created. The tools such as the Team Explorer, Code Coverage, Test View, and Test Results are not new to Visual Studio 2008 but actually available since Visual Studio 2005. While we go through the windows and their purposes, we can check the IDE and the tools integration into Visual Studio 2008. Testing as part of Software Development Life CycleThe main objective of testing is to find the defects early in the SDLC. If the defect is found early, then the cost will be less, but if the defect is found during production or implementation stage, then the cost will be higher. Moreover, testing is carried out to assure the quality and reliability of the software. In order to find the defect earlier, the testing activities should start early, that is, in the Requirement phase of SDLC and continue till the end of SDLC. In the Coding phase, various testing activities takes place. Based on the design, the developers start coding the modules. Static and dynamic testing is carried out by the developers. Code reviews and code walkthroughs are also conducted. Once the coding is completed, then comes the Validation phase, where different phases or forms of testing are performed.
Types of testingVisual Studio provides a range of testing types and tools for software applications. Following are some of those types:
In addition to these types, there are additional tools provided to manage, order the listing, and execute tests created in Visual Studio. Some of these are the Test View, Test List Editor, and the Test Results window. We will look at these testing tools and the supporting tools for managing the testing in Visual Studio 2008 in detail later. Unit testAs soon as the developer finishes the code, the developer wants to know if it is producing the expected result before getting into any more detailed testing or handing over the component to the tester. The type of testing performed by the developers to test their own code is called Unit testing. Visual Studio has great support for Unit testing. The main goal of the unit testing is to isolate each piece of the code or individual functionality and test if the method is returning the expected result for different set of parameter values. It is extremely important to run unit tests to catch the defects in the early stage. The methods generated by the automated unit testing tool call the methods in the classes from the source code and test the output of each of the methods by comparing them with the expected values. The unit test tool produces a separate set of test code for the source. Using the test code we can pass the parameter values to the method and test the value returned by the method, and then compare them with the expected result. Unit testing code can be easily created by using the code generation feature, which creates the testing source code for the source application code. The generated unit testing code will contain several attributes to identify the Test Class, Test Method, and Test Project. These attributes are assigned when the unit test code gets generated from the original source code. Then using this code, the developer has to change the values and assert methods to compare the expected result from these methods. The Unit test class is similar to the other classes in any other project. The good thing here is that we can create new test classes by inheriting the base test class. The base test class will contain the common or reusable testing methods. This is the new Unit testing feature which helps us reduce the code and reuse the existing test classes. Whenever any code change occurs, it is easy to figure out the fault with the help of Unit tests, rerun those tests, and check whether the code is giving the intended output. This is to verify the code change the developer has made and to confirm that it is not affecting the other parts of the application. All the methods and classes generated for the automated unit testing are inherited from the namespace Microsoft.VisualStudio.TestTools.UnitTesting. Manual testManual testing is the oldest and the simplest type of testing, but yet very crucial for software testing. It requires a tester to run all the tests without any automation tool. It helps us to validate whether the application meets various standards defined for effective and efficient accessibility and usage. Manual testing comes to play in the following scenarios:
Manual tests can be created either using a Word document or Text format in Visual Studio 2008. This is a form of describing the test steps that should be performed by the tester. The step should also mention the expected result out of testing the step. Web testsWeb tests are used for testing the functionality of the web page, web application, web site, web services, and a combination of all these. Web tests can be created by recording the interactions that are performed in the browser. These can be played back to test the web application. Web tests are normally a series of HTTP requests (GET/POST). Web tests can be used for testing the application performance as well as for stress testing. During HTTP requests, the web test takes care of testing the web page redirects, validations, viewstate information, authentication, and JavaScript executions. There are different validation rules and extraction rules used in web testing. The validation rules are used for validating the form field names, texts, and tags in the requested web page. We can validate the results or values against the expected result as per business needs. These validation rules are also used for checking the time taken for the HTTP request. At some point in time, we need to extract the data returned by the web pages. We may need the data for future use, or we may have to collect the data for testing purposes. In this case, we have to use the extraction rules for extracting the data returned by the page requested. Using this process, we can extract the form fields, texts, or values in the web page and store it in the web test context or collection. Web tests cannot be performed only with the existence of a web page. We need some data to be populated from the database or some other source to test the web page functionality and performance. There is a data binding mechanism used in Web test, which is used for providing the data required for the requested page. We can bind the data from a database or any other data source. For example, the web page would be a reporting page that might require some query string parameters as well as the data to be shown in the page according to the parameters passed. To provide data for all these data-driven testing, we have to use the concept of data binding with the data source. Web tests can be classified into Simple Web tests and Coded Web tests. Both these are supported by VSTS.
Load testLoad testing is a method of testing used in different types of testing. The important thing with Load testing is that it is about performance. This type of testing is conducted with other types of testing, which means that it can be performed along with either Web testing or Unit testing. The main purpose of load testing is to identify the performance of application based on different scenarios. Most of the time, we can predict the performance of the application that we develop, if it is running on one machine or a desktop. But in the case of web applications such as online ordering systems, we know the estimated maximum number of users, but do not know the connection speeds and location from where the users will access the web site. For such scenarios, the web application should support all the end users with good performance irrespective of the system they use, their Internet connection, the place, and the tool they use to access the web site. So before we release this web site to the customers or the end users, we should check the performance of the application so that it can support the mass end user group. This is where load testing will be very useful in testing the application along with Web test or Unit test. When a Web test is added to a Load test, it will simulate multiple users opening simultaneous connections to the same web application and making multiple HTTP requests. Load testing in Visual Studio comes with lots of properties which can be set to test the web application with different browsers, different user profiles, light loads, and heavy loads. Results of different tests can be saved in a repository to compare the set of results and improve their performance. In case of client server and multi-tier applications, we will be having a lot of components which will reside in the server and serve the client requests. To get the performance of these components, we have to make use of a Load test with a set of Unit tests. One good example would be to test the data access service component that calls a stored procedure in the backend database and returns the results to the application that is using this service. Load tests can be run either from the local machine or by submitting to a rig, which is a group of computers used for simulating the tests remotely. A rig consists of a single controller and one or more agents. Load tests can be used in different scenarios of testing:
Ordered testAs we know, there are different types of testing required to build quality software. We take care of running all these tests for the applications we develop. But we also have an order in which to execute all these different tests. For example, we do the unit testing first, then the integration test, then the smoke test, and then we go for the functional test. We can order the execution of these tests using Visual Studio. Another example would be to test the configurations for the application before actually testing the functionality of the application. If we don't order the test, we would never know whether the end result is correct or not. Sometimes, the tests will not go through successfully if the tests are not run in order. Ordering of tests is done using the Test View window in Visual Studio. We can list all the available tests in the Test View and choose the tests in the same order using different options provided by Visual Studio and then run the tests. Visual Studio will take care of running the tests in the same order we have chosen in the list. So once we are able to run the test successfully in an order, we can also expect the same ordering in getting the results. Visual Studio provides the results of all the tests in a single row in the Test Results window. Actually, this single row result will contain the results of all the tests run in the order. We can just double-click the single row result to get the details of each tests run in the ordered test. Ordered test is the best way of controlling the tests and running the tests in an order. Generic testWe have seen different types and ways of testing the applications using VSTS. There are situations where we might end up having other applications for testing, which are not developed using Visual Studio. We might have only the executables or binaries for those applications. But we may not have the supported testing tool for those applications. This is where we need the generic testing method. This is just a way of testing third-party applications using Visual Studio. Generic tests are used to wrap the existing tests. Once the wrapping is done, then it is just another test in VSTS. Using Visual Studio, we can collect the test results, and gather the code coverage data too. We can manage and run the generic tests in Visual Studio just like the others tests. Software Testing with Visual Studio Team System 2008
Test management and new testing features in VS 2008Visual Studio Team 2008 has great features for working with the type of tests we've just described. These features are greatly improved from the previous versions of VSTS. The Team Explorer, Test View, and Test List Editor are some of those main IDE add-ins used for tests management Team explorerTeam Explorer is the add-on to the VSTS IDE. Using this explorer, the developer or a user of Visual Studio can browse through the Team Projects in the TFS to which the explorer is connected. TFS is the central repository for managing and controlling the team projects. To work with any of the team projects in the TFS, first we have to connect to it using VSTS. After connecting to the server, we can use Team Explorer to browse through the details of the particular Team Project. Team Explorer is a client of TSF and is integrated with the VSTS. Team Explorer provides features to work with the team project details such as:
Team system testing tools introductionVisual Studio 2008 provides many tools to create, run, debug, and view results of the tests for the applications. It is very flexible for running a test and getting the results. Given below is an overview of the tools and windows provided by Visual Studio to view the test details and test output details. We will look into the overview of each of the tools available in Visual Studio 2008.
Let us see how we can create a new testing project using Visual Studio 2008, and then we will test a sample project to get to know about the tools and features. Open Visual Studio 2008 and open the solution of the application which is developed using C# or VB.NET. We will not go into the details of the sample application TestingApp as shown in the preceding screenshot. We will just create a test project for the sample application and see the features of the tools and windows. Now similar to adding the projects and code files to the solution, we have to create the test project and test files and add the test project to the solution. There are different ways of creating test projects under the solution.
For our sample testing application, we will select the second option mentioned above and choose the simple Manual Test (text format) type.
The Add New Test dialog contains nine different template options for creating the tests. There are two different templates for the Manual Test with one using Text file and the other using a Word document. The Unit testing template is of three types; one is for the Database Unit Test, the second one for the general Unit Test, and the third one for the Unit Test Wizard. Following are the file extensions for each of the VSTS test types as shown in the preceding in the image:
After selecting the test type, give a name for the test in the Test Name field. Select the Create new Visual C# test Project… in the Add to Test Project option. We will see more details about this later. For now, consider that we have added the testing project to the existing solution. Now, the system will ask for a name for the new test project. Let us name it TestProjectforTestingApp. Now, we can notice that there are two files created as <ProjectName>.vsmdi, which is the metadata file, and LocalTestRun.testrunconfig file created under the solution for the test projects. The metadata file contains all the information about the tests list. It is an XML file which has all the details. Add two more tests of any type you want. For this example, I have added one more Manual Test using Word document and one Unit test as shown in the Solution Explorer here.
Now, let us see the different windows and tools available in support of all the tests that we can perform using Visual Studio. We will take the sample Manual testing example for getting to know about the tools. Test viewThe Test View window is used for viewing the available tests and also for selecting the test and run it. We can also see the properties of each test from here. It is similar to the solution explorer from where we can get the list of class files in the project. We can also group the available tests based on the type, or owner, or project, or solution, or priority, or any other property of the test. The Test View window can be opened using the Visual Studio IDE menu option Test | Windows | Test View. Now, you can see the following Test View screen which displays a list of all the tests created in the current Test Project.
The screenshot shows the default test view with the list of tests based on the type. We can customize the test view using the filters, grouping and adding or removing the columns. The Test View window has its own toolbar for different operations that can be performed on the list. The left-most option in the toolbar is the run and debug option, by which we can start the VSTS process for running or debugging the selected tests. The second is the Filter option in the toolbar, which contains a drop-down listing of all the columns related to the Test View and the test properties and a box which says <Type keyword> for entering the value that can be used against the field selected in the second drop-down for filtering the list of tests shown. When the button with the arrow next to these drop-downs is clicked, the actual filtering will take place, and the grid will show the filtered list of tests. For example, the following screenshot shows a list of tests filtered with Test Type which are Manual.
The third one is the Group By option which has a drop-down with a list of test properties using which we can group the list of tests available. In the preceding screenshot, remove the criteria entered for the filter in the second drop-down and click on the arrow which will show all the available tests.
The three screenshots below show the tests grouped based on the type. We have two Manual tests and one Unit test. If we select the Group By as the Class Name as shown in the second screenshot, we can see that both of the Manual tests are under No Class Name and the Unit Test is under UnitTest1. Here the class name is no name because the manual tests will not have any classes. Same is the case when we select Description as the Group By field as shown in the third screenshot below. The test which is of type Unit test, and the test which is of type Manual Test are shown together because both these tests do not have a description. The screenshot below shows the tests grouped by Test type. There are two manual tests and one Unit test.
The screenshot below shows the tests grouped by Class Name. The Manual tests does not have class name as it is not derived from any class and does not have a class.
The below screenshot shows the grouping of tests based on the description. The unit test has a description but not the manual tests as there is no description for tests which is of type Manual.
We can change the descriptions of the tests and group them together. Whenever we change the description or class name or an editable property of the test, it will be grouped under that property, if it exists. Otherwise, it will be shown as a new property with that new group. For example, if we change the description of all the tests to Sample Test and group the tests by description, then we can see all the tests grouped together as shown here:
In the Test View, we can select the available columns to display in the view, and we can also sort them using the column header. The following steps explain how to show a column in the view display and how to sort them:
For sorting the columns, click on each column header to change the sorting order. If the same column is already sorted, then the sorting order will be changed. Test list editorAll features available in Test View are also available in the Test List Editor with some additional features. Through this window, we can create the test lists by grouping the available tests. We can also select multiple tests from the list and run them using this window. Whenever we open the Test List Editor using the menu option Test | Windows | Test List Editor, we can see the window as follows showing all the available tests:
The toolbar in the Test List Editor window has the same features that we saw in the Test View window. But you can see that the details section of the list window is split into two panes. The left pane of the window has three nodes, and the right pane displays all the tests in the lists based on the selection in the left pane. The Test List Editor displays the following three options as nodes. Software Testing with Visual Studio Team System 2008
Lists of testsThis is the first node in the list which is initially empty. It also asks us to create the list and add the tests to the list.
We can click on the here link and give the details for the new test list in the window that opens up as Create New Test List. Let's call that test list Manual Tests to group all the available manual tests.
Now in the left pane of the Test List Editor, select the second option Tests Not in a List. Do not check the option but just select the option. This will display all the available tests in the project, which are not part of any other Test list as shown below:
Now choose both the Manual tests on the right pane and just drag and drop them on the Manual Tests node on the left pane, which we created earlier. The other way of doing the same is, after selecting both manual tests, by right-clicking and choosing the New Test List... option. We will get a window similar to what we saw earlier in Create New Test List.
Since we have already created the Test list, we will just drag and drop the tests on the test list name. Now when we select the newly created Manual Tests list, we can both the manual tests listed on the right-side pane.
Now if we select the node Tests Not in a List, we can see only the other tests that we had not selected in our previous steps to add to the Manual Tests list.
Select the third node in the left pane All Loaded Tests. This option will list down all the tests available, whether it is added to a Test List or not. We can also see the Test List name to which a particular test is added; and it will remain empty for the tests which are not part of any of the Test Lists. The following screenshot shows all the loaded tests in the project:
After creating the Test List, we can run the tests based on the list we have created. The purpose of creating the Test List is to group the tests together so that we can run them all together by selecting the Test List using the checkbox option to the left of the test list name and then selecting the Run or Debug option in the toolbar. Each of the nodes in the Test List Editor has checkboxes. Using these checkboxes, we can select the individual tests, a Test List, multiple tests within the Test list, and tests that are not in a list. Then we can run the tests using the Run Checked Tests or Debug Checked Tests option in the toolbar.
There are two more options in editor toolbar: Load Metadata and Import Metadata. These are helpful in loading the existing Test Lists, which are already saved but not available in the current list. This Import and Load refer to the metadata file that gets created for the Test Project under the solution. It's the file with the extension vsmdi, which contains all the information about the tests lists. All other options in the toolbar are the same as the options available in the Test View window such as grouping, filtering, and adding or removing columns. Test resultsThis window shows the results of the tests run. It shows the error messages or the statuses of the multiple tests run. We can also reselect the tests from the Test Results window and rerun the tests. Using this window, we can export the test results or import the results already exported. This is useful in viewing the result in the Test Results window and rerun the test. Now, as we have seen in the previous section about the Test List Editor, select the Manual Tests list and run the tests.
Now, we will consider the test, manualtestdoc as passed, and the test ManualTestText as failed. While running the tests, we can find the tests in progress and the status of the completed tests in the Test Results window as shown below. It's just the starting of the tests. So both the tests are in pending stage.
After completing both the tests, we can see the results as shown in the following screenshot. It will clearly indicate the status for each result. The window also shows the summary of the results, passed and failed. If we want to rerun the test, we don't need to go to the List Editor. From the results window, we can select the tests and rerun them. Using the checkbox before the test in the list window, we can select the test and then choose the Run or Debug option to rerun it.
In the preceding screenshot, we can also notice that there are two panes similar to the Test List Editor. The second option in the toolbar shows the list of Test Lists available and their corresponding tests in the right pane. It is the same option that we saw in the Test List Editor. From the test result, we can also get the details of the test list run. We can get the details such as start time, end time, test location, and the user who ran the test and also the summary of the test results as shown in the following screenshot:
There is another option in the Test Results, which is the option to export the results. Whenever we finish our testing, we always would want to save the results of the tests for our further analysis. In the toolbar, we can see the option for exporting the test results. It provides two options, Export Test Run Results... to export all test results and Export Selected Test Results... to export only the selected test run result. We can also import the saved result using this window.
Once we choose any of these options, we can see the file dialog for saving the file. We can also notice that the file type is *.trx, which is the Visual Studio Test Results file for saving all the test results. The .trx test result file is created by the VSTS on execution of the test every time. The file is named after the user, machine name, the date and time of execution. In the previous image, you can see the test name as Subashni@MyPC 2008-02-16 19:59:50, which shows the name of the user logged in and running the test, the machine name, and then the date and time of execution. The .trx file is an XML file with all information about the test result. If you open the .trx file, it will open the test result window in Visual Studio and show the details in the Test Results window. The contents of the test result file would look like the code shown below. This is just a sample and part of the generated test result file: <?xml version="1.0" encoding="UTF-8"?> Code coverage resultsCode coverage provides information about codes and how many kinds of codes are covered during the test run. This is to view the statistical information about the test run. This result will show how many lines of code are executed and how many lines are not executed. We can also get the color coding for the lines run, and different color coding for the lines not run. This is also a kind of test result. Before starting the code coverage we have to configure the code coverage. Select the Test | Edit Test Run Configurations | Local Test Run option. These configurations are stored in the configuration file, localtestrun.testrunconfig. In the configuration window, select the option Code Coverage in the left pane. On the right-side pane, we can see the list of all the available artifacts for code coverage. The artifacts could be an application, or a library, or any type of assembly. We can choose the artifacts from the list, or we can also import the artifacts using the Add Assembly option and then choose that for the code coverage. As shown in the following screenshot, let us select the test project library, TestProjectforTestingApp.dll.
When we click on apply in the above window, the code coverage is enabled only for the assemblies selected. When the application is executed, we can see the code coverage window collecting information about the source code covered in testing as shown in the following screenshot. The code coverage window is available under the menu option Test | Windows | Code Coverage Results. Lets try running the unit test application available in the test list editor under the Tests Not in a List which has the Unit test. After running the test, we can see the code coverage results as shown in the following screenshot:
The Code Coverage Results window shows each block covered, blocks not covered, and the percentage of coverage for blocks. This applies to each run of the test. Next time we run the same test, we can see a different set of results under a new name. In the Unittest1 class, we can also notice the color coding based on the coverage. This is the code which is covered under testing, and code that is not covered will be highlighted with color coding. After completing the test, we can also export the coverage results similar to the test results. We can also import the coverage results which were already exported. There is another new option, Merge Results. This window will list all the coverage results from which we can select the results and merge them to get the end result of the code coverage collectively from various results. Overview of XML files for testing tools in Visual Studio 2008There are several XML files used by the VSTS Test Edition for storing the test information. All these documents should conform to the schema defined in the TestTypes.xsd file. We have seen some of the XML document types in the previous examples, and here is the summary of all the XML documents for different test types supported by Visual Studio.
XML schema was changed from Visual Studio 2005 Team Edition to the release of Visual Studio Team System 2008 Test Edition. So the XML documents that were created using Visual Studio 2005 Team Edition for Testers need to be upgraded to VSTS 2008 Test Edition before starting to use those XML documents. These XML documents can be converted to the current format using the exe, VSTST-FileConverter.exe. This file accepts one parameter which is the XML document for the test created using Visual Studio 2005. For example, if the test is an ordered test with the name SampleOrderedTest1, then it should be converted using the converter to: >VSTST-FileConverter.exe SampleOrderedTest1.orderedtest To get help on the file converter, we can use the following command: >VSTST-FileCOnverter.exe /help SummaryThis article gave an overview of the different types of testing that we can perform using Visual Studio 2008. We have also looked at how we can create the test project in Visual Studio, and how we make use of different tools that support testing in Visual Studio. Now, we should be able to create and execute a test project and create the test lists. We got an idea of how to view the test results using the Test Results window and look into the Code Coverage Results window. This article also explained about different types of XML and configuration documents that were created during the testing. Software Testing with Visual Studio Team System 2008
About the AuthorsSubashni.S, holds a Bachelors Degree in Computer Science Engineering and has around 10 years of experience in software development and testing life cycle, project, and program management. She is a certified PMP (Project Management Professional) and CSTM (Certified Software Test Manager). She started her career as DBA in Oracle 8i technology and later developed many software applications using Borland software products for a multinational company based in Chennai, India and then moved to Bangalore, India. She is presently working for a multinational company in the area of Project Management for developing and testing projects. Currently working for one of the top multinational companies headquartered at Dallas, Texas and placed at a MNC client in Austin, Texas. N. Satheesh Kumar, holds a Bachelor's degree in Computer Science Engineering and has around 12 years of experience in software development life cycle, project, and program management. He started his career developing software applications using Borland software products in a company based in India. He then moved to the UAE where he continued developing applications using Borland Delphi and customizing Great Plain Dynamics (now known as Microsoft Dynamics) for an automobile sales company. He later moved to India again, spending three years in designing and developing application software using Microsoft products for a top multinational company. A couple of years were also spent in Project Management and Program Management activities. Now he works as a Technical Architect for a top retail company based in the United States. He works with the latest Microsoft technologies and has published many articles on LINQ and other features of .NET. He has also authored LINQ Quickly for Packt Publishing. Books from Packt
|
|
| ||||||||