Microsoft Fakes: Team Build throws IO file not found exception - unit-testing

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.

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

build dotnet solution in travis against netstandard20 and framework462

TLDR; I've got a mixed solution: NetStandard 2.0 for the library I'm actually developing and .Net Framework 4.6.2 (or alternatively dotnetcore 2.0) for the tests. How to configure travis.yml to build the library and the test project as well.
I'm actually working on a client for a rest api. I decided to use .NET Standard 2.0 as project type. As it is a REST based api, I decided to use Newtonsoft.Json to deserialize and serialize the content.
A problem occurred: the nuget package Newtonsoft.Json 10.0.3 doesn't support NetStandard 2.0 by now. But I found the commit ab3315f does. So I cloned the repo and build the netstandard library on my own as a workaraound till the new version is available in NuGet.
I added the project to CI system travis following this post: https://rimdev.io/building-net-core-on-travis-ci/
Now I added a test project to my solution using Nunit to run unit tests and integration tests for my library. No I'm facing 2 problems and I need to solve one:
problem 1: When my test project targets .NET Framework, I'm able to execute all the unit tests without any problems, but now travis complains based on my travis.yml there's no mono installed to build the complete solution correctly.
my question here: how to change my .travis.yml to build both project types within the solution.
problem 2: When my test project targets dotnetcore, my local build works, but when I try to execute tests locally, I get a runtime error:
System.IO.FileNotFoundException : Could not load file or assembly 'Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=null'.
That's why I didn't test travis build by now, as I want to get it running locally first if this is the solution. I don't know why it doesn't find the dependency.
Any suggestions either for problem 1 or for problem 2?
I ended up adding NuGet package of Newtonsoft.Json 10.0.3 to my dotnetcore test project though it is not directly used there. Now the runtime error diappeared. So I am able to test locally and remotely as well and let travis CI build my project.

NCover not finding unit tests

I am trying to install NCover in an existing C# .NET project for work. Unfortunately, after I download NCover and installed the Visual Studio extension, it wasn't finding any of the unit tests. The answers I've seen/heard seem to be in the vain of 'It wasn't working...time passed...it started working.'
I can run the tests with Visual Studio's Test Explorer, but I need to get NCover installed to see the code coverage. I had NCover installed previously, and other people on my team are getting it to work within the same project.
I am using Visual Studio 2013 with the newest version of NCover Desktop (v 5.1).
I am getting two errors in the console log.
The first switches between saying:
Agent Error (v4x64): An error occurred while loading assembly
and
Agent Error (v4x64): There was a problem loading test assembly [test path]. Could not get bytes from loader AppDomain
The second (after I try to run NCover) says it 'Could not load config' for the test dll.
I copied the 4 XML config file (Bolt.ext.config, Bolt.Extension2008.dll.config, NCover.exe.config, ncover.axplorer.exe.config) from one of my team members, so I'm pretty sure that I have my config correct.
Has anyone else experience this/have any suggestions? Help would be greatly appreciated!
Further information:
When I hover over the grayed out test dll in the bolt test panel, I get the following error:
Assembly is not loaded. Select and run to build and load this assembly
I was looking at this post, but it doesn't seem like any of the solutions are working for me...
After working with some of the other developers in my office, we discovered the issue was with the NCover version. For our tests to run, we needed to use NCover v5.0. Neither v5.1 or v5.2 would work with our setup. Not sure what changed in v5.1 that wouldn't let it find the tests, but I'm glad it's working now :)

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!

FluentNhibernate and SQLite

I can't get SQLite Driver working in my sessionfactory.
I downloaded SQLite 1.0.48 from http://sqlite.phxsoftware.com/
I have added the references to System.Data.SQLite in my Tests project.
public static IPersistenceConfigurer GetSqlLiteConfigurer()
{
try
{
return SQLiteConfiguration
.Standard
.InMemory();
}
catch (Exception ex)
{
throw ex;
}
}
This is how I generate the Configurer
The problem is when I build my sessionfactory I get the following error:
NHibernate.HibernateException: The IDbCommand and IDbConnection implementation in the assembly System.Data.SQLite could not be found. Ensure that the assembly System.Data.SQLite is located in the application directory or in the Global Assembly Cache. If the assembly is in the GAC, use <qualifyAssembly/> element in the application configuration file to specify the full name of the assembly.
at NHibernate.Driver.ReflectionBasedDriver..ctor(String driverAssemblyName, String connectionTypeName, String commandTypeName)
at NHibernate.Driver.SQLite20Driver..ctor()
I have tried to change of SQLite version but did not fix the issue.
I can't find what's the problem and I have been working on this for 2 days now.
Let me know if you need more information.
Thanks for the help!
Charles
When I ran into this issue it was caused by running having my application's processor property set to anycpu and running on a 64bit system. To correct the issue I set my application processor property to x86.
I don't think the System.Data.SQLite.dll supports running under a x64 process.
I have fixed my problem by getting the System.Data.SQLite.dll file that is in the FluentNHibernate SVN Repository.
This is now working very well.
I should have checking this earlier ;)
Check, if you are using 4.0 as your target framework. The ADO-driver currently (1.0.66) supports only 3.5.
I am hitting the same problem on a build machine. It works fine when I open the project with Visual Studio, but when I run mstest.exe it fails with the above error. It also fails on my local development machine when I run by command line. Process Monitor shows no attempts to even locate the file by mstest.exe.
The build machine is 32-bit, my local machine is 64-bit. The assembly we are using is the one from the Fluent NHibernate trunk.
UPDATE: Figured it out - mstest.exe wasn't copying all of the assemblies when it was being run from the command line. I updated the localtestrun.config to include them under Deployment. Not sure why the behaviour is different from the IDE and command line test runner.
This issue should be fixed with the lastest NuGet package from Microsoft.
PM> Install-Package SQLitePCL
https://www.nuget.org/packages/SQLitePCL/3.8.2
http://msopentech.com/blog/2014/02/03/new-open-source-portable-class-library-sqlite/