Author: AutomatedQA Corp.
Last updated: June 8, 2009
Applied to: TestComplete 7
Introduction
TestComplete currently has a flawless integration with MSBuild that allows you to run TestComplete’s automated software tests during the local build process initiated by MSBuild.
You can execute TestComplete project suites, projects and automated tests as part
of your MSBuild projects. This allows you to build your application with MSBuild
and automatically perform various automated testing actions at the same time with
the help of TestComplete. By using this functionality in your MSBuild projects,
you can build your applications and achieve all of the benefits provided by TestComplete’s
software testing: working with applications via the user interface and simulating
various user actions, accessing the internal structure of applications, unit testing
and a lot more.
Note that only TestComplete Enterprise edition can be integrated with MSBuild and
provides features for automated testing of applications during the build process
initiated by MSBuild.
Integrating Automated Tests With MSBuild
To use the functionality of TestComplete in your MSBuild projects, you should integrate
TestComplete with MSBuild. When installing TestComplete Enterprise edition on your
computer, select the MSBuild Integration item and either the Microsoft Visual
Studio 2005 Team System Integration or the Microsoft Visual Studio 2008 Team
System Integration item in the installation wizard:
If you select these items, the packages needed for integration will be installed
on your computer. These packages include the assembly named MSBuildTC6Task.dll for
TestComplete 6 or MSBuildTC7Task.dll for TestComplete 7 (the name of this assembly
differs for other TestComplete versions and is named like MSBuildTC*Task.dll, where
the corresponding TestComplete’s version number is placed instead of the asterisk).
The installation program automatically registers this assembly in the global assembly
cache (GAC). Note that the package can be installed only on the computer that has
Microsoft .NET Framework 2.0.50727 or higher installed.
Executing Automated Tests From MSBuild Projects
MSBuild projects are stored in XML files that use the MSBuild XML schema and instruct
the build engine to perform operations during a build process and how these operations
should be performed.
By using the MSBuild project format, you can extend your local builds with advanced
actions that are performed during an automated build process. For instance, you
can perform various automated testing operations after the build has finished. The
MSBuild Integration package of TestComplete gives you the opportunity to execute
TestComplete project suites from your MSBuild project and perform various automated
tests during an automated build process.
The most important type of elements in MSBuild projects are tasks that are
used by MSBuild to perform build operations. For example, a task might compile source
files, run external tools, create and remove files and directories, log errors,
warnings, messages and more. Tasks are grouped by the Target elements
that specify logical structure of the build process and the proper order of tasks.
To run TestComplete’s project suites from MSBuild projects, the MSBuild Integration
package provides the ExecuteSolution task type. Using this MSBuild project element,
you can execute TestComplete solutions, single projects or even project items during
the automated build process. Below is an example of executing a TestComplete project
suite from an MSBuild project:
File: MSBUILD.proj
<!-- Root element of the MSBuild project -->
<project defaulttargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- Declares the task type, ExecuteSolution, that will be used to run TestComplete projects (TC7 is a namespace). -->
<<UsingTask TaskName="TC7.ExecuteSolution" AssemblyName="MSBuildTC7Task, Version=1.1.0.0, Culture=neutral,
PublicKeyToken=e33f56e68d0f845e"/>
<!-- Target -->
<Target Name="Build">
<!-- Executes the task. Note that the tag name, ExecuteSolution, coincides with the registered task name. -->
<ExecuteSolution
SolutionFile="C:\MyProjects\MyProjectSuite.pjs"
StopIfFail="true"
AdditionalOptions="/project:MyProject"
GUIInteractive="true"
LogFile="C:\MyProjects\MyResults.mht"
/>
</Target>
</project>
The example is simple, but it demonstrates the key points of executing a TestComplete
project suite from an MSBuild project. To run TestComplete project suites from your
build project, you should do the following:
- Register the
ExecuteSolution task type. This type of task allows
you to execute the TestComplete project suite. You should always register this type
of task before using it in MSBuild projects, because it is a custom task type. The
registration is done via the UsingTask element. Its TaskName
attribute specifies the task name, and the AssemblyName attribute specifies
the name and properties of the assembly that will perform the task. With the TestComplete
7 integration, it is the MSBuildTC7Task.dll assembly that is a part of the MSBuild
Integration package. For TestComplete 7, the registration string should always be
the same as it is specified in the sample above. To learn what registration string
parameters are used for other versions of TestComplete, see the "Running TestComplete
Tests From MSBuild Projects" topic in the documentation shipped with the
appropriate TestComplete version. - Call the
ExecuteSolution task. Upon registering the task type,
you can use it to specify the desired TestComplete project suite and initiate its
execution from your MSBuild project. The ExecuteSolution element has
a number of attributes that specify TestComplete project suite’s run parameters:
|
Attribute
|
Description
|
|
SolutionFile
|
The full path and name of the TestComplete project suite to be executed.
|
|
StopIfFail
|
Indicates whether the build will fail ("true") or not ("false"), if the TestComplete
task run fails.
|
|
AdditionalOptions
|
A string with command-line arguments that are passed to TestComplete along with
the project suite file name. Via these arguments you can specify, for example, the
project name, the project item or even the name of the routine to be executed. So,
it is possible to execute not only the whole project suite, but even its items.
|
|
GUIInteractive
|
Indicates whether TestComplete ("true") or TestExecute ("false") should be used
to run tests.
|
|
LogFile
|
The full path and name of the .MHT (Multipart HyperText) file. TestComplete exports
test results to this file.
|
Via command-line arguments (the AdditionalOptions attribute of the
ExecuteSolution MSBuild project element) you can specify the names
of TestComplete projects, project items, units and script routines to be executed
from your MSBuild project. Below is the description of the most important combinations
of command-line arguments:
/project:project_name – specifies the name of the project to be run.
/project:project_name /projectitem:item_name – TestComplete
will run automated tests provided by the specified project item.
/project:project_name /unit:unit_name /routine:routine_name
– TestComplete will run the specified script routine declared in the specified script
unit.
If command-line arguments do not exist in the AdditionalOptions attribute,
TestComplete will run the whole project suite specified by the SolutionFile
attribute.
Creating and Building MSBuild Projects
Since MSBuild projects are written in XML, you can create, view and edit them in
any XML editor or even in a text editor (for example, in Notepad). Note that Visual
Studio project files (for instance, .csproj or .vbproj files) are also MSBuild project
files and use the MSBuild XML schema. So, it is easy to view and edit MSBuild project
files in Visual Studio by using its built-in XML Editor.
To create and modify MSBuild project files, you can use another AutomatedQA product
– Automated Build Studio. This powerful tool in
addition to all of its capabilities provides an easy way to create and edit your
MSBuild project files. By using its intuitive user interface, you can quickly and
easily create and edit your MSBuild projects. You don’t need to write XML code!
Just use the desired project elements provided by Automated Build Studio to construct
your MSBuild project and it will create the appropriate XML file.
To execute MSBuild projects, use the MSBuild.exe utility. Note that Visual Studio
uses a hosted instance of MSBuild to execute managed build projects. You can also
run your MSBuild projects directly in Visual Studio and execute TestComplete’s automated
tests during the build process.
Conclusion
As you can see, TestComplete’s integration with MSBuild, allows you to run your
TestComplete automated tests as a part of MSBuild projects and perform various automated
testing actions during your applications build process. We hope this tech paper
will be useful and this information will help you to extend your team builds with
TestComplete’s automated tests making them more flexible and even more powerful. If you are new to TestComplete, download now and try TestComplete for free.