chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
0 votes
We have just recently decided to try Typemock/Isolator with our unit tests. I have been writing some tests utilizing just the basic features of Typemock/Isolator. The application we are developing is targeting .net 3.5 and relying heavily on Windows Process Activation hosted WCF
WCF services. Thus, development is being performed on Windows Server 2008 and the application will be hosted (at least the services) with Server 2008. In attempting to use Typemock/Isolator with Server 2008, I have encountered a halting issue.

We are using NUnit (2.4.7) for unit tests, NCover (2.1) for code coverage, NAnt for builds. We are attempting to run tests that use Type Mock and link them to NCover using the NCover2.0 link either in the configurator or from the command line, or even from MSBuild. For some reason every time we try, we get a coverage file with no results. Furthermore, in using the TypeMockStart element and attempting to run the 2.0 typemock example nunit tests (even on Server 2003) we have an error that TypeMock is not registered. Is this an issue with NCover 2.1 and TypeMock working together? Here's the NAnt build from the example attempt:

<target>
<typemockstart>
<ncover>
<typemockstop>
</target>

I've tried to run this same thing on three different machines (Server 2008, 2003, XP) and recieved the same result (below is the relevant part of the output):


TypeMockCoverage:

[typemockstart] Typemock Isolator Enterprise License - Maintenance will expire in 21 day(s)
[ncover] NCover.Console v2.1.0 (Administrator x86) - Code Coverage Analysis for .NET
[ncover] Copyright (c) 2008 Gnoso Inc.
[ncover] http://www.ncover.com
[ncover] Registered to Customer #: 8173
[ncover] NCover Enterprise Edition (1 User)
[ncover] Command: C:Program FilesNUnit 2.4.7in unit-console.exe
[ncover] Command Args: Examples.csharp.dll
[ncover] Working Directory: C:Program FilesTypemockTypemock IsolatorExamplesCSHARPinDebug
[ncover] Assemblies:
[ncover] ******************* Program Output *******************
[ncover] NUnit version 2.4.7
[ncover] Copyright (C) 2002-2007 Charlie Poole.
[ncover] Copyright (C) 2002-2004 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov.
[ncover] Copyright (C) 2000-2002 Philip Craig.
[ncover] All Rights Reserved.
[ncover] Runtime Environment -
[ncover] OS Version: Microsoft Windows NT 5.2.3790 Service Pack 2
[ncover] CLR Version: 2.0.50727.1433 ( Net 2.0.50727.1433 )
[ncover] .F.F.F.F.F.F.F.F.F.F.F.F.F.F.F.F..F.F.F.F.F.F.F.F.F.F.F.F.F.F.F.F.F.F.F.F.F.F.F.F.F.F.F.F.F.F.F.F.F..F.F.F.F.F.F.F.F.F.F.F.F.F.F.F.F.F.F.F.F.F.F.F.F
[ncover] Tests run: 75, Failures: 73, Not run: 0, Time: 0.438 seconds
[ncover] Test Case Failures:
[ncover] 1) Examples.Tests.NUnit.NaturalMocks.Test1_Basic.MockTheFactoryAlways : TypeMock.TypeMockException :
[ncover] *** Typemock Isolator is not currently enabled.
[ncover] To enable do one of the following:
[ncover] * To run Typemock Isolator as part of an automated process you can:
[ncover] - run tests via TMockRunner.exe command line tool
[ncover] - use 'TypeMockStart' tasks for MSBuild or NAnt
[ncover] * To work with Typemock Isolator inside Visual Studio.NET:
[ncover] set Tools->Enable Typemock Isolator from within Visual Studio
[ncover] For more information consult the documentation (see 'Running' topic)
[ncover] at TypeMock.MockManager.Init(Boolean collectAllCalls)
[ncover] at TypeMock.MockManager.Init()
[ncover] at TypeMock.RecorderManager.a(RecordExpectations A_0)
[ncover] at TypeMock.RecordExpectations..ctor()


One other funny thing - I tried to uninstall 2.1 of NCover and install 2.0.0.1 or whatnot and still got the error. Upon further examination I see that the Profiler version of NCover being loaded is still 2.1.0.0 even though it is running the old console (this is after uninstalling and installing NCover 2.0):

Log from NCover:
(0x00000394) MESSAGE: Profiler Starting
(0x00000394) MESSAGE: NCover Profiler 2.1.0.0
(0x00000394) EVENT: Communications link established.
(0x00000394) MESSAGE: Ready for command input.
(0x00000394) EVENT: Verbose Logging Disabled
(0x00000394) EVENT: Logging Disabled

Please help. I've been working on this issue for days now.
asked by bradgearon (1.5k points)

10 Answers

0 votes
I found another fresh machine to install TypeMock on and attempt. This machine has Windows XP and I installed only NCover 2.0. Directly after installing, I ran the build script mentioned above. I received the same error. The software is supposed to work with 2.0 is it not? What am I doing wrong?
answered by bradgearon (1.5k points)
0 votes
Hi,

The Typemock Isolator software supports working with all version of NCover.
In general you will need to "start" the Isolaotr before running NUint or Ncover.
Take a look at this article about NAnt Build, I think it will help you.
answered by lior (13.2k points)
0 votes
See above in my nant build I have a typemockstart and stop around the ncover element. The output also shows a TypeMockStart message with a message about the license right before the ncover and then test failures:

TypeMockCoverage:

[typemockstart] Typemock Isolator Enterprise License - Maintenance will expire in 21 day(s)

NAnt:

<target name="TypeMockCoverage">
<typemockstart link="NCover2.0" />

<ncover program="C:Program FilesNCoverNCover.Console.exe"
commandLineExe="C:Program FilesNUnit 2.4.7in unit-console.exe"
commandLineArgs="Examples.csharp.dll"
workingDirectory="C:Program FilesTypemockTypemock IsolatorExamplesCSHARPinDebug"
logFile="Coverage.log"
/>
<typemockstop/>
</target>
answered by bradgearon (1.5k points)
0 votes
Finally got this to work using NCover 1.5.8. It works by either linking it via the configurator or via the TypeMockStart element and executing NCover with the exec element (but NOT the NCover). So it seems to be that the issue has something to do 2.0.1/2.1.0. Is there anyway that you can test this and tell me what I'm doing wrong. As with the above that works, I've tried using the configurator to link, running the tmockrunner process with the -link NCover2.0, and using the TypeMockStart link="NCover2.0" solutions all to no avail.
answered by bradgearon (1.5k points)
0 votes
Figured out the 2.1.0 issue also. Apparently you need to add a registerProfiler="false" to the NCover task or execute with the equivalent flag passed in. Then you can use either the typemockstart element or link from the configurator. The documentation says that profilerlaunchedfirst must be true for said typemockstart element, but says nothing about the registerProfiler="false" attribute/flag for NCover. If possible, you should add this bit of information to the instructions so that others don't encounter the same issue.

Thanks for the assistance.
answered by bradgearon (1.5k points)
0 votes
Hi,

First i need to apologize for my mistake earlier (serve me right for not pasting your code segment into a suitable editor).
I'm also glad you could find the answer on your own.
You need to remember that both NCover and the Isolator both uses the same profiler API (which means that they both uses the same registry keys) and that is the reason that you need to explicitly tell the Isolator to "link" with NCover.

Now that you have found the solution it seems quite logical, unless told otherwise the NCover is going to register itself over the "linking" done by the isolator.

:?: Where is the ncover task defined?
I would really like to add examples as you suggest and would like to test them here myself.
answered by lior (13.2k points)
0 votes
I agree completely that with you can't link to a registered profiler and then register a profiler and assume the link is still functional :). Here is the finished and working build. In this, I register the NCover assembly, link to it, runt tests, and then unregister it. This seems to work perfectly. Just need to add the deploy of TypeMock before this happens.

<?xml version="1.0" encoding="utf-8"?>
<project name="TypeMockExample" default="coverage" xmlns="http://nant.sf.net/release/0.85/nant.xsd">

  <!-- Setting up properties replace values with path to nunit, typemock, and ncover -->
  <property name="nunit" value="C:Program FilesNUnit 2.4.7in" />
  <property name="typemock.dir" value="C:Program FilesTypemockTypemock Isolator" />
  <property name="ncover.path" value="C:Program FilesNCover" />

  <!-- Load TypeMock and NCover tasks -->
  <target name="init">
    <loadtasks assembly="${typemock.dir}TypeMock.NAntBuild.dll" />
    <loadtasks assembly="${ncover.path}Build Task PluginsNCoverExplorer.NAntTasks.dll"/>
  </target>
  
  <target name="coverage" depends="init" description="Generate code coverage using NCover">
    <!-- Register NCover profiler assembly NCover.Lib.x86.dll for >= 2.0 (x86) 
      / CoverLib.dll for < 2.0 -->
    <exec program="regsvr32">
      <arg value="-s" />
      <arg value="${ncover.path}NCover.Lib.x86.dll" />
    </exec>
    <!-- Start TypeMock/Isolator; Link to registered profiler -->
    <typemockstart link="NCover2.0" profilerlaunchedfirst="true"/>
    <!-- Run NCover with NUnit; Do NOT register the profiler again -->
    <ncover program="${ncover.path}NCover.Console.exe"
            commandLineExe="${nunit}NUnit-Console.exe"
            commandLineArgs="Examples.csharp3.0.dll"
            workingDirectory="${typemock.dir}ExamplesCSHARPinDebug"
            registerProfiler="false"
    />
    <!-- Stop TypeMock/Isolator -->
    <typemockstop />
    <!-- Unregister NCover profiler assembly -->
    <exec program="regsvr32">
      <arg value="-s" />
      <arg value="-u" />
      <arg value="${ncover.path}NCover.Lib.x86.dll" />
    </exec>
  </target>
  
</project>
answered by bradgearon (1.5k points)
0 votes
Hi,

Thank you for this clean example.
I think that adding this to our guide will help people in the future.

I am however missing one thing, where are these defined?
<ncover program="${ncover.path}NCover.Console.exe" 
            commandLineExe="${nunit}NUnit-Console.exe" 
            commandLineArgs="Examples.csharp3.0.dll" 
            workingDirectory="${typemock.dir}ExamplesCSHARPinDebug" 
            registerProfiler="false" 
    /> 


specifically the definition of "ncover" task
answered by lior (13.2k points)
0 votes
Sorry, the NCover task is defined in this section of the build:

<loadtasks assembly="${ncover.path}Build Task PluginsNCoverExplorer.NAntTasks.dll"/>

This .dll is being referenced from "C:Program FilesNCoverBuild Task PluginsNCoverExplorer.NAntTasks.dll" in this particular case. The NCoverExplorer.NAntTasks.dll is included with the default installation of NCover 2.0+.
answered by bradgearon (1.5k points)
0 votes
I thought so. :)
Its part of the ncover installation.

Again I would like to thank you for all your help.
Ill see how this can be Incorporated into our guide.
answered by lior (13.2k points)
...