I have the following problem, I want to use Ninject in my unit tests.
My thoughts about this were like this:
1) Define a global binding schema inside a module to bind my fake objects that I use inside the tests
2) When using a mock object bind it locally inside the test
I didn’t find a way to locally override the binding configuration, my idea is I locally create a mock object with expectations and I want the kernel.Get() method to return an object that has all the binding in place except that each tests adds a local mock object inside a test with expectations, this sounds to me to be readable and maintainable, as I only override 1 binding per test, the objects are mocks so they can’t be configured inside the module as the test context is unknown
How can I accomplish this, I am using c# and nunit.
If my methodology is wrong I would like to hear the right one.
You shouldn’t use your IoC container to create the object you want to test in your unit tests. Instead create it manually using
newand pass a mock/stub object for each constructor argument.