question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Running test dll in a different folder than the test project folder

See original GitHub issue

I have a project called StandardTest which contains tests and is located in some folder Projects\StandardTest\StandardTest.csproj. If I run one of those tests and call Assembly.GetExecutingAssembly().Location, it returns Projects\StandardTest\bin\Debug\StandardTest.dll.

My solution also contains a second project called CustomTest, which has a reference to StandardTest and is located in Projects\CustomTest\CustomTest.csproj. When I compile CustomTest, the folder Projects\CustomTest\bin\Debug\ contains both CustomTest.dll and StandardTest.dll.

I would like to run the tests defined in StandardTest using the dll located in Projects\CustomTest\bin\Debug\StandardTest.dll. I can easily do this with the console runner, but not with the Visual Studio runner. I need VS in order to debug my tests, so I’m looking for a way to do this using VS. Is it possible?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
CharliePoolecommented, Dec 10, 2018

First let’s dispose of TestContext.WorkDirectory. In NUnit, unfortunately, this has a specific meaning: the directory where work files and reports are created by default. This is not the current working directory and the name was probably a bad choice. User sets work directory to tell NUnit where to put stuff like the XML or any text output. User may also access it in the code and save other things there. Think of it as the directory for saving stuff. 😄

NUnit also supports TestContext.TestDirectory, which is the directory where the current test assembly is located. Note that if you have several test assemblies in different directories, the value will be different when each one of them accesses it. Note also that there is no way you can set the TestDirectory because it’s always where the assembly is located.

The BasePath is a .NET thing. It’s the base directory where assemblies are searched for. You can also have subdirectories listed in the PrivateBinPath. NUnit take scare of all this automatically now, so the old console options are no longer supported. For finding things you want to read at runtime, the TestDirectory and the BasePath will usually be the same thing.

@Wain123 If I missed anything you need to know, please ask.

0reactions
OsirisTerjecommented, Dec 10, 2018

Thanks @CharliePoole . I am adding your comments here to the relevant items in https://github.com/nunit/docs/wiki/Tips-And-Tricks, which lists the options for the adapter (Should probable be a different name on that page, but will do that later)

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to use executables/ DLLs from another folder/location ...
Go to "Unit Test" menu item. Provide root folder for the assemblies to be loaded. (This can be any directory from where you...
Read more >
Allow dotnet test to run on all test projects in a given directory
There is a way to run multiple projects with a single command which returns a single summary for the results. However, you must...
Read more >
Configure unit tests by using a .runsettings file
The number of distinct DLLs in the run determines the actual number of testhosts started. The directory where test results are placed. The...
Read more >
dotnet test command - .NET CLI
The dotnet test command is used to execute unit tests in a given project.
Read more >
Msbuild get directory name. props imported, or something ...
When building the test project, the $ (SolutionDir) is either '' or '*Undefined*'. ... /myoutput # in different directory than project file, with...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found