You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Note: the decision to do or not do this has not been made. Feedback is appreciated.
While the in-memory provider is marketed as "for testing" I think that is somewhat misleading. Its actual main value is as a simple back-end for all our internal non-provider-specific tests.
When we started EF Core, it seemed like it would also be useful for testing applications. This can work with appropriately factored test code and a good understanding of where the provider behavior is different. However, I haven't recommended this for many years, and I don't think anyone else on the team would recommend it either. The main reason is that it's too easy to get caught out by differences in provider behavior, and therefore not realize that the behavior of your test is different from the behavior in production. This can be mitigated by using a provider that is closer to what is being used in production--for example, SQLite. However, the only way to know if something really works is to test with the same code that is running in production.
So, if the only real, non-pit-of-failure approach is to not use the in-memory provider for testing, then maybe we shouldn't ship in 5.0?
On the other hand, it can work for those that understand the limitations, and testing isn't literally the only use for the in-memory provider, even though it is by far (e.g. 99ppfa) the most common.
Reacted by Erik Ejlskov Jensen, Andriy Svyryd, Stephen J White, Brice Lambson, Massimiliano Donini, Lukáš Novotný, Thomas Ottenhus, Isen, Andrey, Henk Mollema and 26 more
Reacted by David Roth, Johannes Hartmann, VagyrMakaan, Morti, Arjan Frans, Thomas Rzipa, Rene Ponudic, Lukas Bickel, codertimu, firatgit and 34 more
I agree with the rationale. But (as user of in-memory provider*) I'd like to see it in 5.0.
To mitigate the concerns about wrong use, one could either
put more emphasis of "the dangers" in the documentation -- the behavior is quite well noted, but can be easily overlooked
remove in-memory from the documentation -- so "no" new user will catch it, whilst anyone who is aware of in-memory can still use it
Of course if the cost for maintaining in-memory is too high, it may be better to just remove it.
But then there's still the old nuget-packages, old documenation that doesn't prevent someone from using it (with more or less success...).
* for tests where no relations, etc. are involved -- just simple inserts, reads, etc. It is easy to setup and reasonable fast for unit-tests as opposed to SQLite or SQL Server. In production the latter is used, so there are -- of course -- tests for more complex scenarios that run against real SQL Server.
Reacted by Arthur Vickers, Jeremy Nicoll, David Roth, VagyrMakaan, Johannes Hartmann, Thomas Ottenhus, Isen, Muhammad Rehan Saeed, Ryouko Konpaku, Federico Paolillo and 5 more
I think it is the right thing to do! We are using Inmemory for our unit testing our micro services, but could just as easily use SQL LocalDB, in fact we already do this in a service where we use SQL Graph.
Always using SQL LocalDB would give us much more confidence in our unit tests, and minimize the amount of "Swagger UI" or integration tests we need to run.
It also seems like you spend a large amount of time making the Inmemory provider work with new features, time which could be well spent elsewhere.
Some feedback first. We've been using a custom provider on top of EF6 that mimicks the quirks of a particular version of Oracle while using an in-memory store. The setup is simple: get the DbCommandTree from EF and instead of generating SQL command text interpret it over the in-mem storage. This gives us a huge productivity boost since we could easily detect problems like unsupported query functions (collation mismatch, outer apply, clob vs varchar operations, etc), expressions that EF would not compile and test basic correctness like constraint checks and foreign keys. Even though it's not particularly optimized we can still run hundreds of tests in mere seconds while spinning up an Oracle test database would literally take minutes, not to mention the overhead of maintaining specific versions.
I'm looking for something similar on top of EFCore. Would this be a good use case going forward for the in-memory provider (assuming it does not get axed)? Or would it be better to build it on top of the relational provider base? I'm not sure where to start, any pointers are welcome.
It would be a pity to lose such a great feature. In-memory is much better for testing than localdb. It is faster and allows isolation testing when I can push partially initialized entities into store.
Reacted by Oskar Klintrot, Tia, Jukka Snellman, Vladimir Makaev, Hannah Chan, Ilya Chumakov, Antoine Milochau, Radek Falhar and GithubOllie
For anyone commenting here, consider that the Sqlite in-memory testing option does exist as an alternative to InMemory. In cases where spinning up the actual database is too costly (e.g. Oracle), Sqlite provides a very high level of relational features (e.g. transactions) while still being extremely easy to set up and fast.
Reacted by Stephen J White, NeVeS, Cédric Luthi, Yunier and kubabuda
Having the InMemory provider makes it really easy for some tasks. In my case I am using it mostly just for local development in the case I have hangfire.io in the app. So I do not have to spin up an sql database (It would not be too hard but in memory is just too easy in that case)
The other are the tests. Here I would not be concerned to switch to sqlite.
Also note that even if we no longer ship the in-memory provider, it is still open source. So anyone that really needs it can create a fork and publish it in a different package. This would likely result in more features being added to the provider by the community as the EF team usually prioritizes them lower than the features for other providers.
@ErikEJ it would mean that we would no longer be maintaining it, making sure it's compatible with latest EF Core versions, etc. The community would have to be responsible for things like adapting InMemory for any provider-facing breaking changes.
Reacted by Erik Ejlskov Jensen and Stephen J White
I never really use the in memory provider, since it doesn't behave like a true DB. As @roji pointed out, Sqlite is an alternative, and a better one, IMO. Suffice to say, I opted to use SQLite in memory for my tests instead of bothering with the one that is the subject of this issue. You won't see any complaints from anyone on my team if you decide to go through with this change.
I found that the InMemory provider gave me more issues than it solved and I ended up today going towards the SQLite provider for testing. But even then the SQLite provider gave one glaring issue when running in memory too and that was I couldn't run EnsureDeleted between each test.
What I'd suggest is to point the InMemory provider to the SQLite in a "in memory" configuration and a EnsureCreated run (maybe?). It might give more value for some this way looking for a quick setup before running into caveats.
We may de-emphasize features in the in-memory provider, but this will be somewhat based on demand for and feedback on these features.
We really appreciate the great discussion that this issue has generated. I think it is pretty clear that while to some people the in-memory provider is not needed, to others it is essential to their development flow. Also, telemetry from VS and VS Code indicates that many developers are referencing the in-memory provider assembly/NuGet package. Therefore, we are not going to remove the in-memory provider.
We have already begun updating our testing guidance to emphasize the trade-offs involved in different testing approaches. We're also going to update this guidance with some samples of different techniques for using the in-memory provider and other providers effectively in tests.
Some features in the in-memory provider (especially query translations) can be very expensive relative to the value they bring. We may de-emphasize these kinds of fixes to free up more resources for other areas. However, we will also consider feedback and will still consider making fixes for things where the demand is high.
Reacted by Soheil Alizadeh, Shodai Ikebe, Martin Andreas Ullrich, Jukka Snellman, Mitchell Cookson, Hannah Chan, Oskar Klintrot, Neil, Ilya Chumakov, Jiří Kanda and 10 more
Reacted by César Souza
Reacted by David Roth, Günther Foidl, Soheil Alizadeh, Ivan R. Perez, Hannah Chan, Johannes Hartmann, Oskar Klintrot, ShutUpAndDoYourJob, Eduardo Couto, Caetano and 1 more
Reacted by Soheil Alizadeh, Martin Andreas Ullrich, Ivan R. Perez, Hannah Chan, Oskar Klintrot, kiddieverts, ShutUpAndDoYourJob, Eduardo Couto, Caetano, ViRuSTriNiTy and 1 more
For anyone else reaching this topic while investigating the in-memory database for testing - there is a dotnet implementation of Java's fantastic TestContainers library, which manages per-test docker containers for your database (or anything else you're integrating with that can be dockerized) and will keep the behavior closer to your database of choice.
Some features in the in-memory provider (especially query translations) can be very expensive relative to the value they bring. We may de-emphasize these kinds of fixes to free up more resources for other areas. However, we will also con
Activity
gfoidl commentedon Oct 18, 2019
I agree with the rationale. But (as user of in-memory provider*) I'd like to see it in 5.0.
To mitigate the concerns about wrong use, one could either
Of course if the cost for maintaining in-memory is too high, it may be better to just remove it.
But then there's still the old nuget-packages, old documenation that doesn't prevent someone from using it (with more or less success...).
* for tests where no relations, etc. are involved -- just simple inserts, reads, etc. It is easy to setup and reasonable fast for unit-tests as opposed to SQLite or SQL Server. In production the latter is used, so there are -- of course -- tests for more complex scenarios that run against real SQL Server.
ErikEJ commentedon Oct 19, 2019
I think it is the right thing to do! We are using Inmemory for our unit testing our micro services, but could just as easily use SQL LocalDB, in fact we already do this in a service where we use SQL Graph.
Always using SQL LocalDB would give us much more confidence in our unit tests, and minimize the amount of "Swagger UI" or integration tests we need to run.
It also seems like you spend a large amount of time making the Inmemory provider work with new features, time which could be well spent elsewhere.
bachratyg commentedon Oct 20, 2019
Some feedback first. We've been using a custom provider on top of EF6 that mimicks the quirks of a particular version of Oracle while using an in-memory store. The setup is simple: get the DbCommandTree from EF and instead of generating SQL command text interpret it over the in-mem storage. This gives us a huge productivity boost since we could easily detect problems like unsupported query functions (collation mismatch, outer apply, clob vs varchar operations, etc), expressions that EF would not compile and test basic correctness like constraint checks and foreign keys. Even though it's not particularly optimized we can still run hundreds of tests in mere seconds while spinning up an Oracle test database would literally take minutes, not to mention the overhead of maintaining specific versions.
I'm looking for something similar on top of EFCore. Would this be a good use case going forward for the in-memory provider (assuming it does not get axed)? Or would it be better to build it on top of the relational provider base? I'm not sure where to start, any pointers are welcome.
kirnosenko commentedon Oct 20, 2019
It would be a pity to lose such a great feature. In-memory is much better for testing than localdb. It is faster and allows isolation testing when I can push partially initialized entities into store.
roji commentedon Oct 21, 2019
For anyone commenting here, consider that the Sqlite in-memory testing option does exist as an alternative to InMemory. In cases where spinning up the actual database is too costly (e.g. Oracle), Sqlite provides a very high level of relational features (e.g. transactions) while still being extremely easy to set up and fast.
stefannikolei commentedon Oct 21, 2019
Having the InMemory provider makes it really easy for some tasks. In my case I am using it mostly just for local development in the case I have hangfire.io in the app. So I do not have to spin up an sql database (It would not be too hard but in memory is just too easy in that case)
The other are the tests. Here I would not be concerned to switch to sqlite.
AndriySvyryd commentedon Oct 22, 2019
Also note that even if we no longer ship the in-memory provider, it is still open source. So anyone that really needs it can create a fork and publish it in a different package. This would likely result in more features being added to the provider by the community as the EF team usually prioritizes them lower than the features for other providers.
ErikEJ commentedon Oct 22, 2019
@AndriySvyryd So "remove" just means "do not publish on NuGet" ?
roji commentedon Oct 22, 2019
@ErikEJ it would mean that we would no longer be maintaining it, making sure it's compatible with latest EF Core versions, etc. The community would have to be responsible for things like adapting InMemory for any provider-facing breaking changes.
stephenjeffreywhite commentedon Oct 22, 2019
I never really use the in memory provider, since it doesn't behave like a true DB. As @roji pointed out, Sqlite is an alternative, and a better one, IMO. Suffice to say, I opted to use SQLite in memory for my tests instead of bothering with the one that is the subject of this issue. You won't see any complaints from anyone on my team if you decide to go through with this change.
jespersh commentedon Nov 14, 2019
I found that the InMemory provider gave me more issues than it solved and I ended up today going towards the SQLite provider for testing. But even then the SQLite provider gave one glaring issue when running in memory too and that was I couldn't run
EnsureDeletedbetween each test.What I'd suggest is to point the InMemory provider to the SQLite in a "in memory" configuration and a
EnsureCreatedrun (maybe?). It might give more value for some this way looking for a quick setup before running into caveats.27 remaining items
ajcvickers commentedon Apr 17, 2020
TL;DR:
We really appreciate the great discussion that this issue has generated. I think it is pretty clear that while to some people the in-memory provider is not needed, to others it is essential to their development flow. Also, telemetry from VS and VS Code indicates that many developers are referencing the in-memory provider assembly/NuGet package. Therefore, we are not going to remove the in-memory provider.
We have already begun updating our testing guidance to emphasize the trade-offs involved in different testing approaches. We're also going to update this guidance with some samples of different techniques for using the in-memory provider and other providers effectively in tests.
Some features in the in-memory provider (especially query translations) can be very expensive relative to the value they bring. We may de-emphasize these kinds of fixes to free up more resources for other areas. However, we will also consider feedback and will still consider making fixes for things where the demand is high.
hauntingEcho commentedon Mar 30, 2021
For anyone else reaching this topic while investigating the in-memory database for testing - there is a dotnet implementation of Java's fantastic TestContainers library, which manages per-test docker containers for your database (or anything else you're integrating with that can be dockerized) and will keep the behavior closer to your database of choice.
Switch to a real database for gateway tests
sebastianstudniczek commentedon Dec 12, 2022
Would you use it in unit testing?