Windows Phone 8 Unit Test App FileNotFoundException - unit-testing

I have a Windows Phone 8 app that I'm trying to unit test. I added a Windows Phone Unit Test App to my project and added a reference to my Windows Phone project. When I try to debug a test in the emulator or my device, I get a FileNotFoundException. It errors in the unit test's MainPage.xaml.cs when it tries to instantiate a TestExecutorServiceWrapper.
It seems like I'm missing some references, but I can't figure out what I'm missing.
Exception Message:
The specified module could not be found. (Exception from HRESULT: 0x8007007E)
Exception:
{System.IO.FileNotFoundException: The specified module could not be found. (Exception from HRESULT: 0x8007007E)
at System.StubHelpers.StubHelpers.GetWinRTFactoryObject(IntPtr pCPCMD)
at vstest_executionengine_platformbridge.MessageTransmitter..ctor()
at Microsoft.VisualStudio.TestPlatform.TestExecutor.TestExecutorServiceWrapper..ctor()
at WinPhoneApp.UnitTests.MainPage..ctor()}
Stack Trace:
at System.StubHelpers.StubHelpers.GetWinRTFactoryObject(IntPtr pCPCMD)
at vstest_executionengine_platformbridge.MessageTransmitter..ctor()
at Microsoft.VisualStudio.TestPlatform.TestExecutor.TestExecutorServiceWrapper..ctor()
at WinPhoneApp.UnitTests.MainPage..ctor()

I ran into this problem as well. I found some good info here: http://dotnetbyexample.blogspot.com/2013/06/x86arm-configuration-gotcha-in-windows.html
Short story: The Windows Phone 8 Unit Test app project is a platform specific project (x86 for the emulator, ARM for the actual device). My WP8 project was AnyCPU, so when I added the test project I tried to make the test project AnyCPU to match my main settings and that resulted in this error.
Adding a config for testing the phone project (as suggested by the blog post linked) solved my problem and my tests now run fine.

So I didn't find out what was the issue with my test project, but I did get it working. I ended up adding a new Unit Test app to my project. I ran the default unit test that is added to a unit test project. It ran fine and there were no FileNotFoundException. So I started adding all my references, including the NuGet references, checking that the unit test ran on each change. Then one by one, I started adding each of the classes in my old unit test app to the new unit test app, and testing the default unit test with each change. After adding all the classes to the new testing project, I didn't get any errors.
So the bad news is I don't know what caused the initial error, but at least I got my new unit test project working.

Related

NUnit3 throws exception System.Runtime, Version=4.2.0.0 not found while trying to run test in NUnit3 console

Environment:
.Net Core 2.0
visual Studio Professional 2017
NUnit3
OpenCover (For code coverage)
ReportGenerator(For code coverage report)
Hi Nunit Team,
I am pretty familiar with MS Test framework and have worked on that extensively but was testing how suitable NUnit framework would be and so wanted to do a small POC around that. I created a small classlibrary and a unit test project. Below are the NuGet package been installed:
NUnit 3.7.1
But when I try to run the test cases from console runner like below I get exception saying System.Runtime, Version=4.2.0.0 assembly not found.
C:\Users\UN\.nuget\packages\nunit.consolerunner\3.8.0\tools>nunit3-console.exe D:\Code_Trials\BoMLibrary\BomTest\bin\Debug\netcoreapp2.0\BomTest.dll
Exception detail:
Errors, Failures and Warnings
Invalid : D:\Code_Trials\BoMLibrary\BomTest\bin\Debug\netcoreapp2.0\BomTest.dll
Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
----> Could not load file or assembly 'System.Runtime, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
Run Settings
DisposeRunners: True
WorkDirectory: C:\Users\Smukherjee.nuget\packages\nunit.consolerunner\3.8.0\tools
ImageRuntimeVersion: 4.0.30319
ImageTargetFrameworkName: .NETCoreApp,Version=v2.0
ImageRequiresX86: False
ImageRequiresDefaultAppDomainAssemblyResolver: False
NumberOfTestWorkers: 4
Am really not sure why so? No matter what I try not able to pass through this error. Moreover, when I try to install the assembly from Nuget I don't even find a assembly with version 4.2.0.0.
Tried installing the version 4.3.0.0 of System.Runtime but no luck. Can you please help on this.
Strange thing, I have got a sample unit test project (as part of opencover nuget install) which targets .Net Framework 4.5 and have NUnit2.6.7 package installed and when I try to run that using NUnit3 console it works like charm.
Even, installing NUnit3 latest stable version 3.10.1.0 doesn't help either. Also, it's surely not an Opencover issue since opencover console just passes the test run request to NUnit console. So the issue has to be around NUnit.
Let me know if you need more information around this.
Found the answer to this here https://github.com/nunit/nunit/issues/2763
NUnit Console doesn't run .NET Core tests - you need to use dotnet test instead. Take a look at this page:
https://github.com/nunit/docs/wiki/.NET-Core-and-.NET-Standard

Microsoft Fakes: Team Build throws IO file not found exception

I am using Microsoft Fakes for my unit testing. On my local dev machine, i can create a fake assembly of a class library and everything works fine. But when check-in the team build on the build server throws
"System.IO.FileLoadException: Could not load file or assembly 'Business.DataAccess.Core, Version=19.0.0.9999, Culture=neutral, PublicKeyToken=925fe695533b6fca' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)"
In my local dev machine 'Business.DataAccess.Core.dll' version is 19.0.0.9999, but on the build server it will be get a proper version number such as 19.0.0.1250.
Business.DataAccess.Core.fakes xml file is as follows. I have removed the version tag.
<Fakes xmlns="http://schemas.microsoft.com/fakes/2011/">
<Assembly Name="Business.DataAccess.Core" />
</Fakes>
I tried both by committing FakeAssemblies folder and not committing it. In both times its not working. My assumption was that fake assemblies will be created at compile time. But it's not working.
How can i get team build to run my unit tests using Microsoft Fakes.
When i fake just the EntityFramework.dll and commit the fake assemblies it works. This proves our build server is equipped with testing MS fakes. Build server has got VS 2013 ultimate version installed.
Much Appreciated!!!
The problem was with 'Business.DataAccess.Core.dll' getting a new version on the build server.
So, To fix this problem, removed 'GlobalAssemblyInfo.cs' file from the project and then in 'AssemblyInfo.cs' added a version.
I had to check-in FakeAssemblies folder with the fake assembly as well for this to work.

Nunit tests are not found on tfs 2013 although NUnit test adapter package is used

I have a simple application and Nunit unit test project with 2 tests to test that app.
I've managed to have unit tests discovered and run locally in Visual studio 2013 but when trying to build application and run these unit tests on TFS 2013 test runner does not find tests ( both projects are built successfully.
No test found. Make sure that installed test discoverers & executors, platform & framework version settings are appropriate and try again.
I've added "NUnit adapter with framework" package to Unit tests project according to answer in this question and committed changes to the TFS.
Unit tests projects is successfully built but still no tests are found. The Test dll fits the **\*Test*.dll naming pattern as configured in the Build Definition.
Why no tests are found? How I can make sure Test Runner is aware of my NUnit test adapter?
If you go to the build, and look in diagnostics (from the web portal), there is a Run VS Test Runner section.
In the same log, there is a Run MSBuild section, it should say "Successfully installed xxxx" where xxx is the name of your adapter package.
Something like:
Check to see that the test runner is successfully restored.
Found the reason - build agent folder in source settings of Build definition was not set correctly - instead of setting it somewhere under build agent working folder I set it outside of it that's why unit tests were not found..
I discovered this using Build process activity log (which was saved in drop folder in my case).this log contains very detailed information (much more than you can see in Visual studio) - there I found in which location test runner is looking for unit tests and then understood what i did wrong.
That's what I saw in log:
Run VS Test Runner00:00:00
Inputs
TestSpecs: BuildParameter[] Array
Enabled: True
ConfigurationsToTest: String[] Array
OutDir:
There were no matches for the search pattern C:\Builds\11\XXXX\Application -Gated\bin\**\*Test*.dll
Hope this will be helpful to someone else.
thanks to everyone who responded to my question!

Resharper NUnit tests failing with Unity

When running NUnit unit tests within Resharper, I'm getting the following error:
SetUp method failed. SetUp : System.IO.FileNotFoundException : Could not
load file or assembly 'Microsoft.Practices.Unity, Version=2.0.414.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies.
The system cannot find the file specified.
If I then "Re-run the failed unit test" they complete (albeit this may take many times of re-runs). Appears to be since I upgraded to Resharper v8 from v7.
Running any of the multiple applications that we are unit testing does not show this error. We are using the ServiceLocator pattern throughout our code.
I appear to have fixed this within the Resharper settings, forcing each assembly to have its own AppDomain whilst running tests. See the third checkbox option down under Resharper -> Options -> Tools -> Unit Testing.
You should check that you used the first version of unity in the main project, because must match to test project and your main project in the meantime you must check all unity dll's.

"Exception occurred while test discoverer was loading tests"

I'm writing a desktop Windows 8 application, and always get this error when building the project:
An exception occurred while test discoverer 'MSAppContainerTestDiscoverer' was loading tests. Exception: Object reference not set to an instance of an object.
I'm using the C++ unit test framework that's built into Visual Studio 2012, and the error doesn't seem to impact my builds or test runs. I haven't found anything about this online; any ideas what causes this error?
Post a build, it seems VS triggers all installed test-adapters (MSTest, et.all) into a discovery phase where they attempt to refresh the list of tests. If during this process, an exception occurs, the above generic error message is shown.
I faced this with NUnit - but you seem to be having the same with MSAppContainer. I'm not sure what that is. It won't affect your builds but may cause tests to be not found.
The NUnit adapter has been modified to log detailed information to the Output window (Tests) in case of a failure. For MSTest, I think this link should help uncover more details