Coder Social home page Coder Social logo

Unit testing EF7 about entityframework.docs HOT 4 CLOSED

dotnet avatar dotnet commented on June 15, 2024
Unit testing EF7

from entityframework.docs.

Comments (4)

VeronicaWasson avatar VeronicaWasson commented on June 15, 2024

Two things that I didn't grok at first:

  • Keep DbContext's isolated; don't re-use the same context to seed the database and then query.
  • Call EnsureDeleted after each test

Another minor gotcha for me: Call EnsureDeleted before calling Assert (in xUnit), so if the assertion fails, you aren't left with stuff in the DB.

from entityframework.docs.

ardalis avatar ardalis commented on June 15, 2024

If you're talking about testing that hits the database, then be sure to call it something other than unit testing. But yes, having an article on integration testing between EF and the database would be great!

from entityframework.docs.

rowanmiller avatar rowanmiller commented on June 15, 2024

We already have #95 tracking this - EnsureDeleted is actually probably not the best as it will cause issues with multi-threaded testing. #95 has details on how to get a database scoped to each test.

from entityframework.docs.

VeronicaWasson avatar VeronicaWasson commented on June 15, 2024

@ardalis: I actually meant using the InMemory provider to unit test other code that calls into EF.

@rowanmiller: Thanks!

from entityframework.docs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.