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
Welcome to Typemock Answers. Here you can ask and receive answers from other community members. And if you liked or disliked an answer or thread: react with an up- or downvote Enjoy!
0 votes
I have TypeMocks v3.7.1 Enterprise installed/enabled on my local machine and on the build server.

The build server has a full install of VS 2005 installed on it with the TypeMock.NET add-in enabled (under the build user account).

If I (and 2 other devs) run the build/tests on my local machine, it works perfectly, but when the automated build runs, the unit tests throw this exception.

TypeMock.TypeMockException: TypeMock.TypeMockException:
*** TypeMock.NET is not enabled, to enable do one of the following:
1. run 'mocking_on.bat' before running the tests
2. run tests via TMockRunner.exe
3. use TypeMockStart tasks for MSBuild or NAnt
4. set Tools->Enable TypeMock.NET from within Visual Studio
For more information consult the documentation (see Running topic).

It has been working for a couple months, but then about a week ago it started to fail and I've been trying to get to run since.

The other weird issue, and I don't know if it is related, is that the Add-in links don't work after the unit tests are run locally. I can open them from the start menu, but if I click on the menu option under the Tools menu, the TypeMock dialog doesn't appear. I really don't care about this issue, but thought it might be part of the issue with the failing builds.

Any help would be appreciated.
asked by (720 points)

7 Answers

0 votes
Hi,
1. Please post how you are building on the build server (cc.net, nant, msbuild)
2. Are you using Coverage? Which one.
3. Post the actual test command
4. What test framework are you using (nunit, mbunit, vstest)

about the second issue, please see if the add-in is enabled.
Open visual studio, Choose Tools->Add In Manager and check TypeMock (both add-in and startup)
answered by (32k points)
0 votes
1. We are building use msbuild (Team Foundation Server)
2. We are using the built in code coverage with VS.NET 2005
3. It is failing when I try to create a mock object.

I created a generic method to handle the casting.

public static T CreateMock<T>()
{
return (T)RecorderManager.CreateMockedObject(typeof(T));
}

When I call this method from my test I get this stack trace along with the error I posted earlier.

at TypeMock.MockManager.Init(Boolean collectAllCalls)
at TypeMock.MockManager.d(Type A_0)
at TypeMock.MockManager.Mock(Type type, Constructor mockConstructors)
at TypeMock.MockManager.MockObject(Type type, Constructor mockConstructors, Object[] args)
at TypeMock.RecorderManager.CreateMockedObject(Type typeToMock)

4. We are using Microsoft's test framework: mstest/vstest

Under the Add-in Manager, the TypeMock add-in is checked and so is Startup. This appears correct.
answered by (720 points)
0 votes
In version 4 you can use:
RecorderManager.CreateMockedObject<T>();


Please post the msbuild section where you run the tests.
answered by (32k points)
0 votes
We are using the default test targets that are part of a default Team Foundation build script. The build includes the build targets from:

C:\Program Files\MSBuild\Microsoft\VisualStudio\v8.0\TeamBuild\Microsoft.TeamFoundation.Build.targets

It runs CoreTest which calls RunTestWithConfiguration which calls into some custom Team Foundation server tasks (TestToolsTask)

<Target Name="CoreTest"
Condition=" '$(RunTest)'=='true' "
DependsOnTargets="$(CoreTestDependsOn)" >

<MakeDir
Directories="$(TestResultsRoot)"
Condition="!Exists('$(TestResultsRoot)')" />

<MSBuild
Projects="$(MSBuildProjectFile)"
Targets="RunTestWithConfiguration"
Properties="BuildNumber=$(BuildNumber);Platform=%(ConfigurationToBuild.PlatformToBuild);Flavor=%(ConfigurationToBuild.FlavorToBuild);IsDesktopBuild=$(IsDesktopBuild)" />
</Target>


<Target Name="RunTestWithConfiguration" >

<TeamBuildMessage
Tag="Configuration"
Condition=" '$(IsDesktopBuild)'!='true' "
Value="$(Flavor)" />

<TeamBuildMessage
Tag="Platform"
Condition=" '$(IsDesktopBuild)'!='true' "
Value="$(Platform)" />

<!-- SearchPathRoot for not Any CPU -->
<CreateProperty
Condition=" '$(Platform)'!='Any CPU' "
Value="$(BinariesRoot)\$(Platform)\$(Flavor)\" >
<Output TaskParameter="Value" PropertyName="SearchPathRoot" />
</CreateProperty>

<!-- SearchPathRoot for Any CPU -->
<CreateProperty
Condition=" '$(Platform)'=='Any CPU' "
Value="$(BinariesRoot)\$(Flavor)\" >
<Output TaskParameter="Value" PropertyName="SearchPathRoot" />
</CreateProperty>

<!-- Test task for the end-to-end build -->
<TestToolsTask
Condition=" '$(IsDesktopBuild)'!='true' and '%(MetaDataFile.Identity)'!=''"
BuildFlavor="$(Flavor)"
Platform="$(Platform)"
PublishServer="$(TeamFoundationServerUrl)"
PublishBuild="$(BuildNumber)"
SearchPathRoot="$(SearchPathRoot)"
PathToResultsFilesRoot="$(TestResultsRoot)"
MetaDataFile="%(MetaDataFile.Identity)"
RunConfigFile="$(RunConfigFile)"
TestLists="%(MetaDataFile.TestList)"
TeamProject="$(TeamProject)"
ContinueOnError="true" />

<!-- Test task for the desktop build -->
<TestToolsTask
Condition=" '$(IsDesktopBuild)'!='false' and '%(MetaDataFile.Identity)'!=''"
SearchPathRoot="$(SearchPathRoot)"
PathToResultsFilesRoot="$(TestResultsRoot)"
MetaDataFile="%(MetaDataFile.Identity)"
RunConfigFile="$(RunConfigFile)"
TestLists="%(MetaDataFile.TestList)"
ContinueOnError="true" />

</Target>

I'm glad that you now included generic methods to help with casting in v4, but I needed that back in 3.7 :)
answered by (720 points)
0 votes
Did you add the BeforeTest/AfterTest target?
(see Integrating with Team Foundation Server)
answered by (32k points)
0 votes
Overriding the BeforeTest and AfterTest targets in the TFS build script worked!

I don't understand why I don't have to do that when I'm running my tests locally. That is very confusing.
answered by (720 points)
0 votes
Hi
When you run the tests locally through Visual Studio TypeMock is enabled
automatically by the TypeMock Add in. (see Tools menu -> Disable TypeMock)
For the full details how to run tests with TypeMock
See Running TypeMock in the documentation
answered by (35.5k points)
...