Resharper launches UnitTest from another location

When I run unit tests using Visual Studio, it works fine because it runs from the project directory where all the assemblies are located. But when I run it using resharper , it goes with error on

var services = Assembly.Load("SomeAssembly"); 

with an error

Failed to load file or assembly "SomeAssembly" or one of its dependencies. The system cannot find the specified file.

So i tried

 var path = Assembly.GetExecutingAssembly().Location; 

and he does not project one. it

C: \ Users \ * UserName * \ AppData \ Local \ Temp \ TestResults \ ... \ Out \

and there is no "SomeAssembly" . How to configure proper resharper setup or build all assemblies like Visual Studio?

Does this happen with unit tests, but not with NUnit, any ideas?

+46
.net-assembly unit-testing nunit visual-studio-2012 resharper
Apr 26 '13 at 7:36 on
source share
10 answers

Reset copies of shadow copies for testing by default. If you turn off the shadow copy, it will be launched in the bin folder and the test should pass. Here are some instructions for turning it off.

+41
Apr 30 '13 at 3:07
source share
β€” -

The documentation for NUnit Gui Test Runner settings has the following note on shadow copying.

Note. If you are tempted to disable the shadow copy to access files in the same directory as your assembly, you should be aware that there are alternatives. Consider using the Assembly.Codebase property rather than Assembly.Location.

Here is an example of using the Assembly.Codebase property

  private string AssemblyLocation() { var assembly = Assembly.GetExecutingAssembly(); var codebase = new Uri(assembly.CodeBase); var path = codebase.LocalPath; return path; } 
+24
Sep 04 '14 at 18:14
source share

I had the same problem, the repeated test runner was in C: \, while the actual built-in dlls and the solution were on a different drive. The solution was to disable β€œUse Legacy Runner” on the MSTest settings page in configuration change options.

+12
Jul 18 '13 at 2:07 on
source share

Try creating a testettings file and configure deployment rules for your tests .

The older versions of resharper seem to have some errors when processing folder deployments , I think this is fixed in the latest version of resharper 7 .

+4
Apr 30 '13 at 18:17
source share

Try this code to download (see below). He will look for builds regardless of the test runner.

 private static string[] assemblyLookupPath = new[] { AppDomain.CurrentDomain.BaseDirectory, Environment.CurrentDirectory, Assembly.GetExecutingAssembly().Location }.Distinct().ToArray(); public static void Assembly Load(string fileName) { var filePath = assemblyLookupPath .Select(f=>Path.Combine(f, fileName)) .Where(File.Exists) .FirstOrDefault(); /*do here null checks and raise errors, write logs, etc*/ return Assembly.LoadFrom(filePath ) } 
+3
Aug 18 '15 at 14:34
source share

You dynamically load your assemblies using Assembly.Load() . Maybe you are missing a build link to download. Otherwise, shadow copying may skip unregistered assemblies.

If you do not want to reference these assemblies, be sure to include them in your project and copy them to the output directory. You can do this by setting the Copy to output directory property "or by creating a custom step after assembly.

+2
Apr 30 '13 at 9:22
source share

To get a very useful answer from mcdon using assembly.Location , you will get the correct answer according to MSFT :

CodeBase is the URL of the location where the file was found, while Location is the path from where it was downloaded. For example, if the assembly was downloaded from the Internet, its CodeBase may start with "http: //", but its location may begin with "C: \". If the file was copied in shadow font, the location is the path to copy the file in the shadow-copy directory.

It's also good to know that CodeBase is not guaranteed for assemblies in the GAC. The place will always be set for assemblies downloaded from disk.

Therefore, I would use the following:

 public static DirectoryInfo GetAssemblyDirectory() { var assembly = Assembly.GetExecutingAssembly(); return new DirectoryInfo(Path.GetDirectoryName(assembly.Location)); } 
+1
Jun 22 '16 at 8:54
source share

Just change the current directory

 var dir = Path.GetDirectoryName(typeof(MySetUpClass).Assembly.Location); Environment.CurrentDirectory = dir; // or Directory.SetCurrentDirectory(dir); 

https://github.com/nunit/nunit/issues/1072

+1
Sep 16 '17 at 20:32
source share

For me, it was decided to set the "Copy Local" property to true in the nunit.framework.dll file in the test project.

0
Nov 07 '16 at 4:50
source share

If you have a problem with starting and building after disabling the shadow build, you must first select "Clear all" from the "Build" option, and then create a project in the "shadow build" disable

0
Nov 27 '16 at 17:25
source share



All Articles