java - Understanding what is going on under the hood of Mockito framework -
I have a problem understanding what is going on in the macro framework. I have the following classes
Model class
value of the public class {Private string key; Private string value; Public string getKey () {return key; } Public Zero Set (string key) {this.key = key; } Public string getValue () {return value; } Public Zero Set Val (string value) {this.value = value; }}
"business logic class"
public class valuefinder {public key ValueMailWellForKee (key value value) {keyValue.setValue ("foo"); Return key quality; }}
Utility class to return expected results (will be velvety)
Public class expatation manager {public string expected value () {return "LoremSpadDolorum"; }}
test class
public class ValueFinderTest {@Test with public zero test} {KeyValueImpl keyValue = Mockito.mock (KeyValueImpl.class); Key value = (new valuefinder ()). FindFail (key value); Candidate Manager Candidate Manager = Mokito Mock (expatnation manager. Class); When (expectationManager.getExpectedValue ()) thenReturn ("somethingDifferentToFoo") .; String expected value = expectationManager.getExpectedValue (); Verify (keyValue) .setValue (expectedValue); // fails, expects "foo", but "some different tofu" - & gt; Verify correctly (main value) .setValue (Expected Manager .getExpectedValue ()); // There is no error, but why? }}
The interesting thing is that the test line is in the last line:
Verify (keyvalue) .setValue (expectationManager.getExpectedValue () ); // There is no error, but why?
I will definitely expect the same behavior in the top row
Verify (keyvalue) .setValue (expectedValue); // fails, "fu" expects but something different - "okay"
Although Mokito walks along with me. Any explanation for this?
I suspect that there is a problem due to the call order. Your last line is effective:
KeyValueImpl
If Mockito is effectively using , a To validate the method call as a marker, "Check it next time, when a cool method is called," it has not been mentioned that this is what the call has been made, then this
expectationManager .getExpectedValue () will be
it has been verified that the call.
I argue that this is a deceptive behavior in Mokoto, I also agree that it is a misleading test - I feel like a design scent - too . I strongly believe in using written fax, wherever possible, to avoid too much contact between mocks, instead of mock.
Comments
Post a Comment