From there you can check/uncheck the changes you want to apply either at a table or row level.
Figure 55-15 shows the comparison results between two versions of a simple Products database.
The upper pane shows the tables and the lower pane shows the records for the selected table. The
Different Records tab in the lower pane will show side by side each Source and Target column, so
you can see where the differences are.
fiGure 55-15
Database Tools .
1093
The Data Compare tool is only able to work with tables in the default schema of
the database.
From the toolbar you can select either Write Updates or Export to Editor to manually apply
the changes.
static analysis
Visual Studio 2010 Premium and Ultimate include static analysis tools for databases as well as for
code. To run the static analysis tools, select Data . Static Analysis . Run. Currently, 14 rules are
spread across three categories to help you develop databases: Design, Naming, and Performance.
transact- sql editor
This editor allows you to work with Transact-SQL (T-SQL) code directly in Visual Studio. To open
it, you can double-click a .sql file in Solution Explorer or from the Schema View of a Database
Project. Another option is to start with a blank editor — to do this go to Data .
Transact - SQL
Editor and select New Query Connection. Now you can start to write your T-SQL, with nice
coloring and most of Visual Studio’s shortcuts and features like bookmarks and search and replace.
From the toolbar or the T-SQL Editor menu, you can validate syntax, execute your code, include
client statistics, disconnect to work offline, and reconnect once you need to run a query. When you
run the queries, the results can be displayed on a grid or text format or be exported to a file. You
can also change this behavior from the menu or toolbar.
best Practices
The following is a list of best practices we compiled through our work with Database Professionals
and which have worked for us on small and medium-sized projects:
.
Each developer works with his own local SQL database instance, one for development and
another for testing. This is necessary to isolate uncommitted and untested changes and avoid
affecting other developers working on the database at the same time. It is strictly necessary
for managed-code debugging purposes, because starting a debugging session will cause all
managed threads to stop. From the project properties for Database Projects, you can specify
the database to target for each Solution Configuration, but SQL-CLR projects can only
target one database.
.
Each developer works with two databases, one for development and one for unit testing
because different data will be used for each.
.
Use (local) or 127.0.0.1 for the hostname instead of, say, MikesComputer or 192.168.2.6,
which would work only on one machine.
.
If you are using database instances, be sure all your developers have an instance with the
same name.
1094 .
chaPter 55 ViSuAl STudio ulTimATe For deVeloperS
.
All developers should have the same SQL Server version. Although SQL Server Express can
be used for design-time validation and testing purposes, some features, like Text Indexing,
are not supported.
.
Clear the Block Incremental Deployment if Data Loss Might Occur checkbox in the project
properties window for the Solution Configuration used for Test Databases. Because you will
have a Data Generation Plan, data will be easy to re-create after changes have been made to
the schema.
.
When deploying to a production database, build the Database Project and then modify the
build script to manually deploy it to the server. You can lean on the Schema Comparison
tool to have a more granular view of the changes made.
suMMary
In this chapter, you saw a couple of advanced features that are part of Visual Studio 2010 Premium.
All of these target quality improvement. Code Metrics and the Analysis Tool will analyze your code
or binaries statically, collecting metrics and evaluating rules. The metrics will be useful to see how
maintainable your code is. For the analysis, you have rules for different categories that will help you
ensure that your code will perform well before it runs. On the other hand, the Profiling Tools will
evaluate your code at run time and IntelliTrace lets you explore the execution of your application
during a debugging session.
This chapter covered some of the most important features for database developers. You saw how
easy it is to develop code for SQL-CLR and how the Offline Schema Projects will help you work on
a team, versioning and merging your changes. Advanced features like refactoring and unit testing
will change the way you develop databases, and tools like Schema Compare, Data Compare, Data
Generation, and the T-SQL Editor will support the process as well.
56 56
Visual studio Ultimate
for Testers
what’s in this chaPter?
.
Testing web and windows applications
.
Identifying relationships between code and tests
.
Planning, executing, and coordinating testing tasks
.
Managing test environments
You can test an application in many ways. Chapter 11 introduced the concept of unit tests,
which are small executable pieces of code that verify a particular aspect of behavior for a
single method or class. The first part of this chapter examines the advanced tools built into
Visual Studio that are available for other testing tasks, including testing web applications and
databases. You also learn how to track the relationships between tests and code.
The 2010 release of Visual Studio also contains a new product called Test and Lab Manager.
This tool is designed for testers to interact directly with Team Foundation Servers and manage
test plans, suites, and cases. Test and Lab Manager is available with the Ultimate edition of
Visual Studio and as a part of a separate pack called Test Elements.
autoMated tests
An automated test is a piece of code that verifies the behavior of your application without
any user input or control. Once the system has been asked to run an automated test, it can
be left unattended until it has completed. To create a new automated test from Visual Studio
1096 .
chaPter 56 ViSuAl STudio ulTimATe For TeSTerS
2010, use the Test . New Test menu option to display the Add New Test dialog shown in
Figure 56 - 1.
fiGure 56-1
Depending on which edition of Visual Studio you have, you might not have all of
the tests shown in Figure 56 - 1. Coded UI Tests and Database Unit Tests are only
available in the Premium and Ultimate editions. Web Tests and Load Tests are
only available in the Ultimate edition. The rest of the automated tests are available
in all three editions.
web Performance tests
This type of automated test simulates web requests and allows you to inspect the responses and
evaluate different conditions to determine if the test passes. When you create a new Web Test,
Internet Explorer opens with the Web Test Recorder enabled, as shown in Figure 56-2. Navigate
to and around your site as if you were a normal user. Once done, simply click Stop. This opens the
Web Test’s designer shown in Figure 56-3. There you can customize your test, adding validation
and extraction rules, context parameters, comments, data sources, and calls to other Web Tests, or
inserting transactions. You can also specify response time goals for requests.
You will often need to run the same set of tests against different web servers; to do this you
configure which server the test runs against as a context parameter. From the Web Test Designer
you can right-click the main node and select Parameterize Web Servers. Visual Studio will inspect
the URLs in each request and determine the context parameters it will need to create.
automated Tests .
1097
You can link your requests using the output from one of them as input for the next; to do this, you
add extraction rules to a specific request. You can extract from fields, attributes, HTTP headers,
hidden fields, and text, or even use regular expressions. The result of an extraction will set a context
parameter, which can then be used, for example, as a form or query string parameter in further
requests. You could add a product and then search for it using the ID in another request.
fiGure 56-2
fiGure 56-3
You can add form and query string parameters from the context menu of a request. By selecting
a form or query string parameter from the properties window, you can set its value to a context
parameter or bind it to a data source.
1098 .
chaPter 56 ViSuAl STudio ulTimATe For TeSTerS
No test framework would be complete without validations. When you record a test, a Response
URL Validation Rule is added asserting that the response URL is the same as the recorded
response URL. This is not enough for most scenarios. From the context menu at a Web Test or
request level, you can add validation rules. You can check that a form field or attribute has a certain
value or that a particular tag is included, find some text, or ascertain that the request doesn’t take
more than a specified length of time.
Double-clicking the .testrunconfig file in Solution Explorer allows you to further customize
how Web Tests are run. There you can choose the number of iterations, the browser and network
type, and whether the test engine should simulate think times. You can have many Test Run
Configurations and from the Test menu select the active one.
Web Tests, as well as any other type of test, are displayed in the Test List Editor window as you
saw in Chapter 11. From there you can run your Web Test and group it inside a particular test list.
You can also run it directly from the Web Test Designer. Once a test is run you can see its details
by double-clicking it in the Test Results window. To open this window, select Test Results from the
Test Windows menu. There you can see each request’s status, total time, and bytes. When you select
a request you will see the details of the selected request and received response, values of the context
parameters, validations and extraction rules, and a web-browser-like view displaying the web page.
An example is shown in Figure 56-4.
fiGure 56-4
If you need additional flexibility, you can code the Web Tests using .NET and the Web Testing
Framework. The best way to learn how to use the framework and start coding your test is by
generating code for a recorded Web Test. You have this option in the Web Test context menu.
automated Tests .
1099
Although Visual Studio provides some ASP.NET-specific features, you can use
Web Tests for sites built using other technologies.
load tests
Whereas web and load testing are meant to test functional requirements, Load Tests will run a set
of tests repeatedly so you can see how your application will perform. When you create a new Load
Test, you are presented with a wizard that guides you through the necessary steps. First, you need to
create a scenario; here you will define if you want to use think times. When you recorded the Web
Tests, the time you took between each request was also recorded and can be used as the think time.
It can be edited for each Web Test request in the properties window.
As part of the scenario, you will define the load pattern; for example, a constant load of 100 users
or a load incrementing by 10 every 10 seconds until you get to 200 users. The next steps, Test,
Browser, and Network Mix, define how tests will be run by virtual users, specify which browsers
will be used to run the tests, and determine the kinds of network that will be simulated. In the Test
Mix step you can add Generic, Ordered, and Web Tests.
In the Counter Sets step, you add the computers that you want to monitor and the performance
counters you are interested in. For example, you can monitor your Database Server and IIS. In the
last step, Run Settings, you can specify the test duration or test iterations, how often samples will be
taken for performance counters, a test description, how many identical errors will be recorded, and
the validation level. We defined a validation level for each Validation
Rule in our Web Tests. Because evaluation of these rules can be
expensive, in Load Tests only rules with a level equal to or below
the specified validation level will be evaluated.
When you click Finish, you are presented with the Load Test Designer
as shown in Figure 56-5. There you can add additional scenarios,
counter sets, or new run settings.
When you run the tests, you will see the Load Test Monitor; by
default it will show the Graphs view. In the left-side pane you have a
tree view of the counters that are being collected. You can select items
there to add them to the graphics. From the toolbar, you can change
to Summary or Tables view, export to Excel or CSV, and add analysis
notes. In the Graphs view at the bottom, you will have a legends pane
as shown in Figure 56-6. There you can select/deselect the counters
that you want to include in the graphs. While the test is running, the
monitor is updated on each sample interval. In the Tables view, you
can see the Requests, Errors, Pages, SQL Trace, Tests, Thresholds,
and Transactions.
fiGure 56-5
1100 .
chaPter 56 ViSuAl STudio ulTimATe For TeSTerS
fiGure 56-6
Thresholds are particularly important. These are values for each performance counter that will allow
you to spot problems. In the graphs, you can see points where violations occurred marked with a
warning or error icon.
Test load agent
For large-scale applications, one computer might not be enough to simulate the desired load. Visual
Studio Team System 2010 Test Load Agent can distribute the work across different machines. It can
simulate approximately 1,000 users per processor. This product requires a separate installation and
requires one controller and at least one agent. To configure the environment, select Administer Test
Controller from the Test menu. There you can select a controller and add agents. Then, from the