MEF and unit testing with NUnit -


A few weeks ago I jumped on MEF (Component Modell) bandwagon, and now I'm using it for a lot of plugins And in the shared library altogether, this is often different from mistakes in my part, thereby causing disappointing debugging sessions.

Either way, my app is running very well, but due to a change in my MEF-related code, I automate fails. Most of my unit tests simply failed because I was testing module dependent on other modules which were required to be loaded by MEF. In these situations, bypassing the MEF and working directly in the instantification of those objects.

In other words, MEF through me

  [import] public ICandyInterface ci; Set; Public Series MyCandy: [Iconic Constructor] Public MyCandy ([Import ("name_param") ( 

and

  [Export (typeof (ICandyInterface)]] name of string {} ...}  

But in my unit test, I just

  the candy interface MyCandy = new CandyInterface ("Godiva"); In addition, candy infages need a connection to a database, on which I have just worked on adding a test database to my unit test folder, and I have access to NUnit Testing is for everyone. 

OK, so here are my questions about this situation:

  1. Is there a bad way to do this?
  2. Part [set up] in [set up]
  3. I have not yet learned how to use socks in unit testing - is this a good example of that matter Where do I need to return the dummy data (somehow) to the underlying database connection and actually do not have a database?
  4. If you get something like this before, can you have your own experience and the way you can solve your problem? (Or should this go to the community wiki?)

It looks like you The correct track should be a unit test to test the unit , and this happens when you make a direct example. If you make MEF an example for you, then they integration tests < / Strong> It is not that there is nothing wrong with the integration test, but unit tests are more powerful Es as you examine in isolation each unit.

I usually advise against setting up the fixtures in the setup. This leads to anti-pattern.

The best practice to replace dependence is. Dynamic socks are more versatile than doing this, so surely you should learn something.


Comments