I am a bit confused about how to correctly mock an object. From what I have seen in the example on NSubstitute, this is the basic setup for an assert. My understanding is this is about testing the behavior of the method. My questions are as follows:
Is this the correct way to mock getting a host name of a device.
[TestMethod] public void MockedDeviceHostName() { //Arrange var device = Substitute.For<IDeviceLogic>(); Device mockedDevice = new Device(); //Act device.GetHostName("IP Address","Object Identifier Repository","CommunityString").Returns(mockedDevice.hostName); //Assert Assert.AreEqual(mockedDevice.hostName, device.GetHostName("IP Address", "Object Identifier Repository", "CommunityString")); }
What is the advantage of mocking. I of course understand this is behavior based testing, I mean in terms that I am setting the behavior expectations so I feel they will always be correct even if there is an error with the method, in this case. I am looking for a bit of clarity on mocking vs Unit Tests and integration tests.