I am not an MSTest user, but you probably have several options. Normally with NUnit I would use a generic or parameterized device, but I'm not sure if MSTest has similar capabilities. In light of this, here, as I would do it with NUnit in a form that should be reproducible using any unit test structure using the template template template .
Steps:
- Define an abstract base class using all tests in it
- Insert the abstract CreateStorageManager () method, which returns the IStorageManager (or something else) interface of the two dependencies to implement)
- Subclass twice and provide an implementation of CreateStorageManager (), which returns the specific type that you want to use to run the tests.
Here's the code for the equivalent version of NUnit; I'm sure you can extrapolate. Note. . The inheritance rules for MSTest may differ slightly from what I'm used to. If this does not work, you can try marking the base class as test equipment.
public abstract class PasswordManagerFixtureBase { protected abstract IStorageManager CreateStorageManager();
MSTest may be a more elegant way to do this, but it should work.
source share