MustBeCalled Ignored on Static Method

4 posts, 0 answers
  1. Jeff
    Jeff avatar
    2 posts
    Member since:
    Aug 2013

    Posted 31 Dec 2013 Link to this post

    I thought that MustBeCalled would fail on the Assert in the following situation but the test passes (note, no call is made to the "MustBeCalled" method). 

     

    Public Class Foo

        Public Shared Sub Bar()

           Debug.Print("Wahoo!")

        End Sub

    End Class

     <TestMethod()> _

     Public Sub Foo_Test()

         Mock.SetupStatic(GetType(Foo), Behavior.Strict)

         Mock.Arrange(Sub() Foo.Bar()).MustBeCalled()

         Mock.Assert(GetType(Foo))

     End Sub

     
    I am using version 2013.3.1119.2 of JustMock in Visual Studio 2012 and I have verified that the Profiler is enabled. If I don't arrange the Foo.Bar call, the test fails, as expected because the behavior is set to Strict. Is there another way to do the Arrange or Assert so that this works as expected? 

  2. Stefan
    Admin
    Stefan avatar
    198 posts

    Posted 31 Dec 2013 Link to this post

    Hello Jeff,

    Mock.Assert(obj) works only for mock instances - not for types. Currently, there is no way to assert all expectations on a given type. Instead, you can assert the Bar() method directly, like so:

    Mock.Assert(Sub Foo.Bar());
    The above will assert whatever expectations have been previously arranged for this method. If no expectations were arranged explicitly, then it assumes a MustBeCalled() expectation and asserts that.

    Regards,
    Stefan
    Telerik
    Share what you think about JustTrace & JustMock with us, so we can become even better! You can use the built-in feedback tool inside JustTrace, our forums, or our JustTrace or JustMock portals.
  3. DevCraft R3 2016 release webinar banner
  4. Jeff
    Jeff avatar
    2 posts
    Member since:
    Aug 2013

    Posted 31 Dec 2013 Link to this post

    Perfect! Thanks for the quick response!
  5. Stefan
    Admin
    Stefan avatar
    198 posts

    Posted 01 Jan 2014 Link to this post

    Thank you, Jeff

    I'm glad that this resolved the issue for you.

    Regards,
    Stefan
    Telerik
    Share what you think about JustTrace & JustMock with us, so we can become even better! You can use the built-in feedback tool inside JustTrace, our forums, or our JustTrace or JustMock portals.
Back to Top