This is a migrated thread and some comments may be shown as answers.

MustBeCalled Ignored on Static Method

3 Answers 87 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Jeff
Top achievements
Rank 1
Jeff asked on 31 Dec 2013, 03:03 PM

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? 

3 Answers, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 31 Dec 2013, 03:15 PM
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.
0
Jeff
Top achievements
Rank 1
answered on 31 Dec 2013, 03:26 PM
Perfect! Thanks for the quick response!
0
Stefan
Telerik team
answered on 01 Jan 2014, 07:22 AM
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.
Tags
General Discussions
Asked by
Jeff
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Jeff
Top achievements
Rank 1
Share this question
or