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
What in AAA can tell me what was mocked and which mocks were called and with which arguments? I used to use MockManager.Verify(); Then the test would throw an exception and fail if any expected mocks were not called. That did the job although I'm not convinced that I needed to fail the test as long as my assertions passed. I would just like to log what was mocked. When reviewing a failed test I could review this information and know where NOT to look without having to read the test code. When reviewing all passed tests this could still be useful in reflecting on code dependencies.


Thanks
-Tom
asked by trp (4.1k points)

6 Answers

0 votes
Hi Tom,

One of the main drives behind the AAA approach is to separate the test Arranging phase (setting up test data) from the Act phase (executing the code under test) and from the Assertion phase (verifying everything went as expected). In our AAA API that last part is provided by the Isolate.Verify entry point. This is comparable to the test framework's Assert statement in that that it fails the test if the verification fails. In example, this is how we verify a call has been made:
Isolate.Verify.WasCalledWithAnyArguments(() => fake.DoSomething(0); // the argument value is ignored
Isolate.Verify.WasCalledWithExactArguments(() => fake.DoSomething(0); // the argument value is checked


Please let me know if this helps.

Doron
Typemock Support
answered by doron (17.2k points)
0 votes
I want to log or verify what was mocked. I can Isolate.Verify.WasCalledWith... to verify that a method was called but not to verify that a static call was mocked or for that matter ( I don't think it works when using ) instance calls. )

10x
-T
answered by trp (4.1k points)
0 votes
????
answered by trp (4.1k points)
0 votes
Hi Tom

Sorry for the late reply :oops:
Verify that a static method was called is done the same way as instance method:
// Arrange
Isolate.WhenCalled(() => ClassWithStaticMethod.StaticMethod()).WillReturn(5);

// call your code under test ....

// Verify for a static method.
Isolate.Verify.WasCalledWithAnyArguments(() => ClassWithStaticMethod.StaticMethod());


Hope it helps.
answered by ohad (35.4k points)
0 votes
That method ALWAYS throws an exception for faked methods. I want to see if the fake of the method was called.

10x
-T
answered by trp (4.1k points)
0 votes
Hi Tom,


Using Isolate.Verify checks two things:
1. The method was faked in some way
2. The method was called.

It will throw exception only if the faked method was not called or if the method was not faked in some way.

If you add a call to the method it shouldn't throw an exception.

I was wondering why do you want to check if a method was mocked - do you have some test logic that depends on it?

Dror
Typemock Support
answered by dhelper (11.9k points)
...