How to run SQL tests from IDE
Wondering how to run tests from visual studio or rider IDE. Problem is that no provider is set up when running either on windows or mac. Can we get a unit test provider which targets .NET portable possibly? We are using bundle_green but it won't set a provider, we used to have the ide test functionality working in windows on the older version of SQLitePCL.raw by adding the windows sqlite library into the PCL project which would copy it over into the bin/net45 directory.
I assume you are talking about running your own test cases which happen to involve a dependency on SQLitePCL.raw.
The SQLitePCL.raw provider is platform-specific (because the native sqlite library is platform specific) and must be initialized from platform-specific code.
If you have a dependency on bundle_green, you just need to figure out a place to call SQLitePCL.Batteries_V2.Init().
But the details of how to do that will depend on a great deal on how your test and runner are set up.
Yeah we have tests which are using sqlpretty which are dependent on sqlitepcl.raw. The resharper test runner host runs our tests from a PCL .netportable project. Unfortunately I can't figure out any way to have the test host set the provider before running the tests. For now if I call SQLitePCL.Batteries_V2.Init() it will only be bait and not actually do any detection as to which SQLite provider to use, is it possible to use a .netportable provider which can detect the platform at runtime? For now we are looking at manually referencing the .net45 provider to pull in the e_sqlite library which will be copied over when running the PCL unit tests project on either windows or mac.
"is it possible to use a .netportable provider which can detect the platform at runtime?"
Nothing like that currently exists. If it did, I imagine there would be lots of problems with it. But I can see how it might be handy for very simple cases and for testing.
We have something working now though it's not pretty. We manually link the .NETPortable class library to the .NET45 SQLitePCLRaw.provider.e_sqlite3.dll (it can't be added via nuget) so we can call SetProvider from the .NETPortable class library. The below code uses batteries init for the actual app code, and uses SetProvider in the test code. The .NETPortable class library which holds the tests, links to the e_sqlite3.dll and libe_sqlite3.dylib and copys them over into the bin directory so they will be found when running the tests.
try
{
// The TestHarness runner app for Android/iOS/cli etc. provides the sqlite3 library.
// It's not up to this PCL to provide an actual SQLite3 DLL implementation by itself.
SP.Batteries_V2.Init();
}
catch(Exception ex)
{
// something unexpected went wrong, bail out completely
if (!ex.Message.Contains("is the 'bait'")) throw;
// we're probably running inside an IDE, so use the one that's been provided by
// call the .net 4.5 provider to load the dll for us.
SP.raw.SetProvider(new SQLite3Provider_e_sqlite3());
}
Closing old/stale issue.