Think about what it is you're actually interested in testing. For your GetExpectedTech
method, you're passing in a string and returning a Tech
. presumably there is some connection between the string passed in and the Tech
returned. That's what you should be testing (not null probably, contains expected values etc).
If a side effect of the method is that the Tech
is stored in a field of the class, then you must be doing it for a reason (if not you shouldn't be doing it). Currently there's no reason in the code you've posted, however the most likely reason would seem to be that there will be other methods in the class that use that Tech
or return it. At the point you can link the two methods up to create a relationship between the two methods. There's nothing wrong with calling multiple methods on your SUT if the relationship between the methods is part of what you're trying to test, so you could do:
var expectedTech = sut.GetExpectedTech(someString);
var otherTech = sut.DoSomethingElse(someOtherParams);
Assert.AreEqual(expectedTech, otherTech);
If it's interactions with the Tech
that you need to test for other methods, then you may need to look at creation patterns so that you're able to inject a Mock into your SUT, but without knowing what else your class does it's hard to say if this would be necessary or not.
As you've said, you can access the member using reflection, or PrivateObject however the number of scenarios where this is the right thing to do are relatively small, so if you need to do that, it could be a sign that your class needs refactored.