Typemock Isolator NAnt Tasks

TypeMock has several task for NAnt:

Note: To run nUnit with Typemock Isolator, nUnit must be run in a new executable and the <exec> task is used (the <nunit2> task will not work).
It is a good practice to run the executable to support different NUnit versions than that distributed with NAnt.


typemockstart Task

Professional and Enterprise Edition Only (see Typemock Isolator Editions)

Start using Typemock Isolator

Parameter

Type

Description

Required
version
String

Typemock Isolator version output

False
target
String

Can be used to change the .NET version. Possible values:

  • 1.1
  • 2.0
False
profilerlaunchedfirst
Boolean

Indicates that the code coverage is run before the test application

False
link
String

Links a Code Coverage tool with Typemock Isolator. The profilername is the same name that appears in the Typemock Isolator Configurator.

False
loglevel 0-9 Verbose level of the log to create False
logpath String Path to save log files (defaults to Typemock Isolator installation directory) False
Examples
The following code runs NUnit tests with Typemock Isolator.
<?xml version="1.0"?>
<project name="Typemock Isolator Examples" default="test" basedir=".">
<property name="nunit" value="C:\Program Files\NUnit\bin\nunit-console.exe" />
<property name="typemock.dir" value="C:\Program Files\TypeMock\TypeMock Isolator" />

<!--Example: running NUnit tests with Typemock Isolator-->
<target name="test">
<!-- Dynamically load Typemock NAnat tasks -->
<loadtasks assembly="${typemock.dir}\TypeMock.NAntBuild.dll" />
<!-- Start Typemock Isolator -->
<typemockstart/>

<!-- Execute tests using NUnit -->
<exec program="${nunit}" failonerror="false">
<arg value="Tests.dll" />
</exec>

<!-- Stop Typemock Isolator -->
<typemockstop/>
</target>
</project>

The following code runs NUnit tests with Typemock Isolator and NCover2.x coverage (of Tests.dll) in .NET 2.0. This is done using the <ncover> NAnt task provided with NCoverExplorer, which comes with the NCover 2.x installation.
<?xml version="1.0"?>
<project name="Typemock Isolator Examples" default="test" basedir=".">
<property name="nunit" value="C:\Program Files\NUnit\bin\nunit-console.exe" />
<property name="ncover.dir" value="C:\Program Files\NCover\NCover.Console.exe" />
<property name="typemock.dir" value="C:\Program Files\TypeMock\TypeMock Isolator" />

<!-- Example: running NUnit tests with Typemock Isolator and NCover 2.x coverage -->
<target name="test" description="Execute NUnit tests with Typemock Isolator, and generate coverage information with NCover 2.x">
<!-- Dynamically load TypeMock Isolator NAnt tasks -->
<loadtasks assembly="${typemock.dir}\TypeMock.NAntBuild.dll" />

<!-- Load NCover NAnt tasks -->
<loadtasks assembly="${ncover.dir}\Build Task Plugins\NCoverExplorer.NAntTasks.dll" />

<!-- Start TypeMock Isolator; Link to the NCover profiler -->
<typemockstart target="2.0" link="NCover2.0" profilerlaunchedfirst="true" />

<!-- Run NCover with NUnit; Do NOT register the NCover profiler - this conflicts with the Typemock/NCover link -->
<ncover program="${ncover.dir}\NCover.Console.exe"
commandLineExe="${nunit}"
commandLineArgs="Tests.dll"
registerProfiler="false"
/>
<!-- Stop Typemock Isolator -->
<typemockstop />
</target>
</project>
Note: Typemock Isolator requires registering its own profiler when linking with the NCover profiler. If not using the registerProfiler="false" flag, NCover will try to register its profiler when run and unregister Typemock Isolator, causing unexpected test failure.
Note: You can use the same syntax for usage with NCover 1.5.8 by downloading the NCoverExplorer Extras package. The following example shows using NCover 1.5.8 with NAnt's <exec> task.

The following code runs NUnit tests with Typemock Isolator and NCover 1.5.8 coverage by using the generic NAnt <exec> task.
<?xml version="1.0"?>
<project name="Typemock Isolator Examples" default="test" basedir=".">
<property name="nunit" value="C:\Program Files\NUnit\bin\nunit-console.exe" />
<property name="ncover.dir" value="C:\Program Files\NCover\NCover.Console.exe" />
<property name="typemock.dir" value="C:\Program Files\TypeMock\TypeMock Isolator" />

<!-- Example: running NUnit tests with Typemock Isolator and NCover 1.5.8 coverage -->
<target name="test" description="Executes NUnit tests with Typemock Isolator, and generates coverage information using NCover 1.5.8" >
<!-- Dynamically load TypeMock Isolator NAnt tasks -->
<loadtasks assembly="${typemock.dir}\TypeMock.NAntBuild.dll" />

<!-- Start TypeMock Isolator; Link to the NCover profiler -->
<typemockstart target="2.0" link="NCover" profilerlaunchedfirst="true" />

<!-- Run NCover with NUnit using the NAnt exec task -->
<exec failonerror="false" program="${ncover.dir}\NCover.Console.exe">
<arg value="${nunit}" />
<arg value="Tests.dll" />
</exec>

<!-- Stop Typemock Isolator -->
<typemockstop />
</target>
</project>

typemockstop Task

Stop using Typemock Isolator.
This task should always be called after typemockstart

Parameter

Type

Description

Required
undeploy
Boolean Undeploy previously autodeployed Typemock Isolator False


typemockregister Task
Professional and Enterprise Edition only (see Typemock Isolator Editions)

Register Typemock Isolator License

Parameter

Type

Description

Required
company
String

The Company Name received in your license

True
license
String

The activation key received in your license

True
autodeploy
Boolean Run Typemock Isolator Tests without installing False
Example
<?xml version="1.0"?>
<project name="Typemock Isolator Examples" default="test" basedir=".">
<property name="typemock.dir" value="C:\Program Files\TypeMock\TypeMock" />

<target name="register">
<!-- Dynamically load TypeMock task. -->
<loadtasks assembly="${typemock.dir}\TypeMock.NAntBuild.dll" />
<typemockregister company ="TypeMock" license="TypeMockLicense"/>
</target>

</project>

Copyright © Typemock Ltd. 2004-2008. All Rights Reserved.