问题
I have started to use rider for developing in Linux with C#. I have created my tests like:
namespace RAWConverter
{
using NUnit.Framework;
[TestFixture]
public class SerializationHelperTest
{
[Test]
public void SerializeEntry()
{
msRun msRun = new msRun();
SerializationHelper.SerializationEntry(System.IO.Path.GetTempFileName(), msRun);
}
[Test]
public void DeserializationEntry()
{
msRun msRun = SerializationHelper.DeserializationEntry(getFileNameFromResource(RAWConverter.Properties.));
Console.WriteLine(msRun.endTime);
}
private string getFileNameFromResource(String fileName)
{
String strAppPath = Path.GetDirectoryName(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName);
String strFilePath = Path.Combine(strAppPath, "resources");
return Path.Combine(strFilePath, fileName);
}
}
}
and I have a folder in my project called resources that contains the file. However when I execute my tests it fail because this variable
System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName
is in /usr/bin
Any ideas?
回答1:
The bin folder is the default output directory where the project binaries are copied to and executed from when the project is built. If you were to manually copy the resources folder and its contents to the bin folder the test would work.
I am not familiar with the IDE in question but I suggest checking if there is a setting that will allow for resources to be automatically copied to the output directories when the project is built.
Found a comment in their community
Editing file properties - Copy to output directory
We are about to publish new EAP build in couple of days, and in that new build "Build Action" and "Copy to output directory" are drop-downs.
For now you may press F4 on project in SolutionExplorer and edit Include manually.
来源:https://stackoverflow.com/questions/44053289/adding-resource-file-for-testing-in-rider