none
How to Unit Test RRS feed

  • Question

  • I am trying to write unit tests for my application. This is the setup: MVC 4 Web Api Application using entity framework. We are working with data from an existing database.

    As it is right now, I can't test 80% of the code written so far since it performs CRUD operations on the database.

    So, how do I write the code in such a way it is unit testable given the current setup? Documentation would be great. I've searched for some but I can't seem to find anything that applies. Maybe I am searching with the wrong search terms. Is there training that my company can pay for that I could attend? Or, how would I go about finding somebody who would fix some of the code that exists and train me and maybe some others on how to do this?

    Thanks!

    Eric

    Thursday, November 8, 2012 3:29 PM

Answers

  • Friend,
      Unit testing is something which a unit of our applicaiton or code is tested. If there is a data access layer in between, we might need to use a mock framework to inject a dummy data layer which provide expected. Also dependency injection to inject those objects dynamically while testing.

    Two things you need to use here are... Dependency Injection and Mock framework.

    Microsoft unity framework will help you in implementing Dependency Injection and Rhino Mock will help you in mock the interfaces. Which i am using in my apps.


    -- Thanks Ajith R Nair

    • Marked as answer by Eric Coffman Thursday, November 8, 2012 11:21 PM
    Thursday, November 8, 2012 3:41 PM

All replies

  • Friend,
      Unit testing is something which a unit of our applicaiton or code is tested. If there is a data access layer in between, we might need to use a mock framework to inject a dummy data layer which provide expected. Also dependency injection to inject those objects dynamically while testing.

    Two things you need to use here are... Dependency Injection and Mock framework.

    Microsoft unity framework will help you in implementing Dependency Injection and Rhino Mock will help you in mock the interfaces. Which i am using in my apps.


    -- Thanks Ajith R Nair

    • Marked as answer by Eric Coffman Thursday, November 8, 2012 11:21 PM
    Thursday, November 8, 2012 3:41 PM
  • Thank you Ajith, there is a lot to read through. I am going to mark your reply as answer for now. Thanks!
    Thursday, November 8, 2012 11:21 PM