How to get path in project folder from unit test

billboard

I have a unit test project and library project. I want to use the pdf file in library project as template. When I use Environment.CurrentDirectory I get path of the unit test project, but I want to get the path of the library project to reference pdf file.

Path.Combine(Environment.CurrentDirectory, "../PDFs/template.pdf"); 

What is the equivalent statement to get path to file in library project when executing the unit test?

BradleyDotNET

You can't. The unit test project has a copy of the referenced assembly in its bin folder and that doesn't know about the original "source" location (nor should it).

Unit tests should be able to execute in a vacuum, not relying on something to exist elsewhere in the filesystem (or ideally not rely on the filesystem or other external resources at all).

The only way to solve the problem as posited is to ensure that your "template.pdf" is copied to the output directory of the unit test, probably with a post-build step. A much better approach would be to just include the template in the unit test project.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

how to get the rest of path from sub folder

How to get file path from folder wpf?

How to get parent folder name from path

How to fix "Failed to get workspace folder from test item" for a Java tester project in VS Code?

How to get files from a project folder

How to get the path of a sub folder under root directory of the project in python?

How to get absolute path to file in /resources folder of your project

How to get path of root directory of your project folder in Perfect 2.0?

How to unit test a vsix project?

How to get folder path from file path with CMD

How to get src/main/java classloader from unit test

How to get Spannable and its color from TextView to write a unit test

Unit Test: How to get a Configure class from the ServiceCollection

How to get relative path of the file that is exist in project folder in .net core project

How can I get the last folder from a path string?

How to get parent folder from path in C++

How with bash to get from a path all but the first folder

How to recursive get absolute path from list of folder objects?

How to get selected folder path from file picker in Android

How to get folder path of Installed application, from Visual Studio 2012

How to get images from the .tex folder (relative path) in Rmarkdown?

How to define Test Data Sheet path in eclipse if the file is saved in project folder

how to get unit test working?

How to get the path of an internal folder?

How to select a folder and get folder path in grails?

DeploymentItem(Path, outputDirectory) not working in new Unit-Test project

How to Unit Test a project with Multiple Configurations

How to add an assembly reference in unit test project?

Get direct path of database.mdf from project folder - file moved