locked
How to unit test EF code easily RRS feed

  • Question

  • User828542847 posted

    we use EF to do CRUD operation. now tell me how could i unit test of those code without insert/ update data in db?

    anything new as such has been added in EF core for unit test which help us to generate unit test code easily instead of manually writing code?

    Monday, July 3, 2017 5:33 PM

Answers

  • User-832373396 posted

    Hi tapan,

    I guess that this is what you actually need.

    Please refer to this article :

    'When writing tests for your application it is often desirable to avoid hitting the database.  Entity Framework allows you to achieve this by creating a context – with behavior defined by your tests – that makes use of in-memory data.' From https://msdn.microsoft.com/en-us/library/dn314429%28v=vs.113%29.aspx?f=255&MSPPError=-2147217396 

    And it uses a mocking framework ;

    With Regards,

    Angelina Jolie

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, July 4, 2017 10:19 AM

All replies

  • User-832373396 posted

    Hi tapan,

    I guess that this is what you actually need.

    Please refer to this article :

    'When writing tests for your application it is often desirable to avoid hitting the database.  Entity Framework allows you to achieve this by creating a context – with behavior defined by your tests – that makes use of in-memory data.' From https://msdn.microsoft.com/en-us/library/dn314429%28v=vs.113%29.aspx?f=255&MSPPError=-2147217396 

    And it uses a mocking framework ;

    With Regards,

    Angelina Jolie

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, July 4, 2017 10:19 AM
  • User828542847 posted

    thanks for pushing me to right direction. just like to know that do i need to write a repository on top of EF crud operation for unit testing? is it mandatory to write repository.

    Tuesday, July 4, 2017 11:33 AM