MSTest DeploymentItem attribute causes SQLite.Interop.dll not found - mstest

The suite of unit tests I have immediately fails the test run with System.DllNotFoundException: Unable to load DLL 'SQLite.Interop.dll' which is a dependency required within the test [AssemblyInitialize] methods.
I've determined this is caused by executing any test that is using the [DeploymentItem] attribute and is the case for either a class or method. Any tests that do not use this attribute pass.
With Test Diagnostic logging enabled in VS2019 there are no obvious errors but I can see this config.
<RunSettings>
<RunConfiguration>
<ResultsDirectory>D:\Dev\****\src\TestResults</ResultsDirectory>
<SolutionDirectory>D:\Dev\****\src\</SolutionDirectory>
<TargetPlatform>X86</TargetPlatform>
<CollectSourceInformation>False</CollectSourceInformation>
</RunConfiguration>
</RunSettings>
My test projects are all configured for <PlatformTarget>AnyCPU</PlatformTarget> so I wonder if the SQLite.Interop.dll is not found because of an issue with x86 vs x64.
Where can I configure the <RunSettings>?
Why would SQLite.Interop.dll not be found?
UPDATE
Using procmon.exe filtering for testhost.exe and SQLite.Interop.dll I can see that a test without [DeploymentItem] attributes starts looking for the dll in the project bin\Debug folder which finds it at bin\Debug\x64\SQLite.Interop.dll.
Those tests with the attribute starts looking in the Test Results directory TestResults\...\Out then all across the machine C:\Windows, C:\Program Files, C:Users but never further under bin\Debug.
Running the same tests using VSTest.Console.exe does not have this issue.
How can I apply System.Data.SQLite from NuGet, interop dll not copied to output directory to the .\Out directory for the unit tests?

To resolve;
Configure unit tests by using a .runsettings file
Add setting <DisableAppDomain>True</DisableAppDomain>, see Configure a test run
Note that run settings cannot be retained at the project or solution level and need to be set in the IDE; https://developercommunity.visualstudio.com/content/problem/151608/ability-to-set-runsettings-in-project-file.html

Dave Anderson's answer did help, however we load custom modules into SQLite and this caused the 'Attempted to read or write protected memory' error. The work around for me was to remove <DisableAppDomain>True</DisableAppDomain> and use
[DeploymentItem(#"x86\SQLite.Interop.dll", "x86")]
[DeploymentItem(#"x64\SQLite.Interop.dll", "x64")]
on all tests or classes that needed to use SQLite

Related

Maven Test with Evosuite-generated Test Cases

I am using Evosuite to generate test cases for my app via Maven and I've followed all of the steps that are outlined in the Evosuite documentation.
I see that all of the test classes have been generated and the export copy the classes to the test folder of my project, so I should be able to run mvn test to run the tests, but when I do, I get a series of errors that it cannot find a bunch of classes (it looks like it can't find any of the Evosuite classes from the runtime even though I have the evosuite runtime defined as a dependency in my POM.)
I would love to use Evosuite for all of our apps but if I cannot get the mvn test to run without errors then the product is useless. Can anybody help with this? I have gone over the documentation several times and checked everything and it all appears to be configured correctly. Thank you.
If you have already run mvn evosuite:export to move them to the ./src/test folder then you may need to compile them using javac so they can be executed by maven. Try using this article to compile them all within one command: How to compile multiple Java files when there are Java files in other packages?

PGO instrumented VSTest.Console.exe

I'm trying to run some tests on a DLL that has been instrumented with PGO. When I run it with the VSTest.Console.exe, I get the following error message:
Error message:
Failed to set up the execution context to run the test
My goal is to produce some PGC files for the DLL to see if the compiler can produce better code. BTW, the same thing happens with MSVS.
Does anyone have advice where I may find a PGO instrumented VSTest.Console.exe or another method for what I need?
Placing this DLL in the same directory as the targeted DLL, allows me to produce PGC files.
pgort140.dll

MsTest unable to copy test data files to build server

I am trying to implement automated unit testing with each build using TFS.
Problem statement :
I have created few xml files which stores test data and set to copy always. When run locally files are picked up from bin folder. When I schedule a build, build process looks for files in out folder under TestResults on Build Server. Out folder contains ddls but not the xml files. Hence unable to find files and results into build failure partially.
You can specify additional files to deploy in your test settings file:
More details here - https://msdn.microsoft.com/en-us/library/ms182475.aspx
You could also use the DeploymentItem Attribute.
https://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.unittesting.deploymentitemattribute.aspx

BDD Tests are not recognized in command level

I am trying to run Specflow BDD tets in command line and looks like it doesn't recognized those tests. But I am able to run them in VS IDE
Not sure whether there is a path issue.
I tried other options as in the below link as well. No luck though
How do you run SpecFlow scenarios from the command line using MSTest
The Problem was, that the code-behind files of the feature files were not generated properly, because the configuration of the unitTestProvider was missing.
See the documentation for that here: http://www.specflow.org/documentation/Configuration/

boost unit test with visual studio test adapter - set working directory

I'm trying to use boost unit tests, integrated into VS (2013) using the Visual Studio Test Adapter. My unit test tests a library that requires another DLL to be present in its working directory (it's linked by specifying the .lib in 'additional inputs' under linker settings, not through 'References'). I cannot adjust the global PATH (need to be able to reference multiple versions on one machine). Furthermore, my tests require some test data that is searched for relative to the current working directory.
Without the boost unit test adapter, I just set the working directory under 'debugging' or run the unit test executable from a command line, where the current working directory is obvious.
My question: how do I set the current working directory for the test to be run using the boost unit test adapter. I tried setting 'command' and 'working directory', and looked in the documentation of the adapter for a way to set the directory. None of that has helped. How is this supposed to work?
I had the same problem like you did. The best workaround I found was to define a global fixture, that sets the current working directory.
#include <boost/test/unit_test.hpp>
#include <boost/filesystem.hpp>
struct SetPwd {
SetPwd() {
boost::filesystem::current_path("." /* Your path here.*/);
}
~SetPwd() {
}
};
BOOST_GLOBAL_FIXTURE(SetPwd);

Resources