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 Community! Here you can ask and receive answers from other community members. If you liked or disliked an answer or thread: react with an up- or downvote.
0 votes
I have a use case for unit tests that extend a base class for common class initialization and cleanup work. Using MSTest, this code looks like this:
[TestClass]
public class BaseTestClass
{
    [TestInitialize]
    public void BaseTestInitialize()
    {
        Console.WriteLine("BaseTestInitialize");
    }
}

[TestClass]
public class TestingClass : BaseTestClass
{
    [TestInitialize]
    public void TestInitialize()
    {
        Console.WriteLine("TestInitialize");
    }
    
    [TestMethod]
    public void TestSomething()
    {
        Console.WriteLine("TestSomething");
    }
}


If I run this code using the test explorer in visual studio, and TMockRunner.exe, I get the following output, which I am expecting:
BaseTestInitialize
TestInitialize
TestSomething


Running the same TestSomething test from the SmartRunner plug-in or by clicking the shield and running the test, I get the following:
TestInitialize
BaseTestInitialize
TestSomething


It just looks like the SmartRunner is running the initialization methods in the wrong order. TestCleanup works as expected because it probably uses the same logic as the piece handling TestInitialize today.

I'm using TypeMock 7.3.0.0 and the associated plug-in that gets installed with that version. Has this bug been addressed in newer versions of TypeMock or is there a suitable workaround?
asked by dnglaze (1.4k points)

13 Answers

0 votes
Quick update. I installed TypeMock 7.4.2 and reproduced the same issue using the SmartRunner from Visual Studio.
answered by dnglaze (1.4k points)
0 votes
Hi,

You are right. This is a bug, we've reproduced it here.

We'll fix it and get back to you. As a workaround, you probably want to remove the TestInitialize from the base, and call the method directly from the TestInitialze method:

[TestClass]
public class BaseTestClass
{
//[TestInitialize]
public void BaseTestInitialize()
{
Console.WriteLine("BaseTestInitializ
}
}

[TestClass]
public class TestingClass : BaseTestClass
{
[TestInitialize]
public void TestInitialize()
{
base.BaseTestInitialize();
Console.WriteLine("TestInitialize");
}

[TestMethod]
public void TestSomething()
{
Console.WriteLine("TestSomething");
}
}

Thanks for letting us know,

Gil Zilberfeld
Product Manager
answered by gilz (14.5k points)
0 votes
Hi,

Please find the Patch for this issue here.

Let us know if it helps.
answered by alex (17k points)
0 votes
Patch fixed my tests that used the base initialization method. For some reason, it made all my other tests break, but I assume that's because the installer you provided was a patch. It wouldn't let me install the patch until I uninstalled 7.4.2. Reinstalling the official 7.4.2 release got me back to my original state.

With patch installed, however, my logs did verify that things are happening in the right order. Thanks!
answered by dnglaze (1.4k points)
0 votes
Hi,

Thank you for the feedback.
Although it's a patch, it shouldn't have broken your other tests.
Please send us info about the broken tests so we can fix it.

Is there anything in common between the broken tests?
Which error messages did you get?
answered by alex (17k points)
0 votes
When using the version you provided, I get a new error pop up when I start Visual Studio. Something about checking the ActivityLog. When I look there, the only warnings are related to string load failures and duplicate template IDs in some DevExpress packages.

In addition to that, all the shields that usually sit next to the unit tests no longer show up as if the plugin is having trouble parsing the tests. The tests just look like they fail to pass, but the test navigator is unable to navigate to the tests. I'm not able to actually see why a given test failed, be it an exception or just a failed assert. I turned logging on and looked through the log files. There isn't really anything there, as far as I can tell. The actual testing logs show "Finish (failed): " with no message. Is there supposed to be a message there as to why the test failed?

Test Explorer in Visual Studio is still able to execute and pass all unit tests.
answered by dnglaze (1.4k points)
0 votes
Hi,

Thanks for letting us know. It seemed we have a merge problem where the runner functionality got affected (for the worse, obviously).
We're looking into it, and will get back to you soon.

Cheers,
Gil Zilberfeld
Product manager.
answered by gilz (14.5k points)
0 votes
Any update on this? It's not blocking me from getting work done, but it is disappointing to not see green shields :D
answered by dnglaze (1.4k points)
0 votes
Hi,

I tried to send the patch straight to your email, not sure why it got lost.

You can download the patch from here.
Let me know if it helps.
answered by alex (17k points)
0 votes
Alright, so that version seems to pass all of my unit tests, the ones that use the base class initialize and the ones that don't.

The problems I'm now having are that the shields do not show up in the editor. As it turns out, there was an exception during startup that was cause by some extension. Reading the activity log, I see the following error:
<entry>
  <record>685</record>
  <time>2013/10/31 15:31:28.733</time>
  <type>Error</type>
  <source>Editor or Editor Extension</source>
  <description>
  System.InvalidOperationException: A member of type 'TypeInfo' must have exactly a single accessor of type 'TypeInfo'
      at System.ComponentModel.Composition.ReflectionModel.LazyMemberInfo.GetAccessors()
      at System.ComponentModel.Composition.ReflectionModel.ReflectionExtensions.ToReflectionMember(LazyMemberInfo lazyMember)
      at System.ComponentModel.Composition.ReflectionModel.ReflectionMemberExportDefinition.GetDisplayName()
      at System.ComponentModel.Composition.ReflectionModel.ReflectionMemberExportDefinition.System.ComponentModel.Composition.Primitives.ICompositionElement.get_DisplayName()
      at System.ComponentModel.Composition.ErrorBuilder.CreateCannotGetExportedValue(ComposablePart part, ExportDefinition definition, Exception innerException)
      at System.ComponentModel.Composition.ExceptionBuilder.CreateCannotGetExportedValue(ComposablePart part, ExportDefinition definition, Exception innerException)
      at System.ComponentModel.Composition.Hosting.CompositionServices.GetExportedValueFromComposedPart(ImportEngine engine, ComposablePart part, ExportDefinition definition)
      at System.ComponentModel.Composition.Hosting.CatalogExportProvider.GetExportedValue(CatalogPart part, ExportDefinition export, Boolean isSharedPart)
      at System.ComponentModel.Composition.Hosting.CatalogExportProvider.CatalogExport.GetExportedValueCore()
      at System.ComponentModel.Composition.Primitives.Export.get_Value()
      at System.ComponentModel.Composition.ExportServices.GetCastedExportedValue[T](Export export)
      at System.ComponentModel.Composition.ExportServices.&lt;&gt;c__DisplayClass4`2.&lt;CreateStronglyTypedLazyOfTM&gt;b__1()
      at System.Lazy`1.CreateValue()
      at System.Lazy`1.LazyInitValue()
      at System.Lazy`1.get_Value()
      at Microsoft.VisualStudio.Text.Utilities.GuardedOperations.InstantiateExtension[TExtension,TMetadata](Object errorSource, Lazy`2 provider)
  </description>
</entry>


Was there a slight mixup in the editor extension part of TypeMock?
answered by dnglaze (1.4k points)
...