7 Replies
Both seem okay to me. In TestMethod2 I would call localServiceMock a test implementation or stub rather than a mock but it's still a valid way to unit test.
Edit: I guess I'm assuming that LocalServiceWraperTest is created specifically for testing and is not your runtime implementation. It's hard to understand since all your classes have the word test/example in the name.
LocalServiceWraperTest is implemented
@p.armytank i have updated the code to remove this the uncessary use of
test
suffix to make it clearerOk, now I understand better. So is LocalServiceWraper the class that you're trying to test? In that case method 2 is better - you want to use the concrete implementation. In method 1 you are just testing a mock, which is pointless.
problem is if i have something like a for loop inside
TransformDoSomething
method
resultValues.Length
results in null referenceYes because you are not injecting IThirdPartyService into LocalServiceWraper. You should be using constructor injection to create the instance of ThirdPartyService. Then in your test you would pass your thirdPservicemock into the constructor of LocalServiceWraper.
i will test this and see how it works, but in advance of that i just want to say thanks for the help :thankuwu:
its actually looking impossible to do contructor injection because the thirdParty Lib is using a
static method to for loading
as opposed to a constructorI'm talking about the constructor for LocalServiceWraper. You would pass in the instance of IThirdPartyService to LocalServiceWraper's constructor, and then use that instance in TransformDoSomething.