添加资源文件以在Rider中进行测试 [英] Adding resource file for testing in Rider
问题描述
我已经开始使用Rider在Linux中使用C#进行开发.我创建了如下测试:
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
位于/usr/bin
有什么想法吗?
推荐答案
bin文件夹是默认的输出目录,在此目录中,项目二进制文件将在构建项目时复制到该目录并从中执行.如果您要手动将资源文件夹及其内容复制到bin文件夹,则测试可以进行.
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.
我对所讨论的IDE不熟悉,但是我建议检查是否存在一个设置,该设置允许在构建项目时将资源自动复制到输出目录.
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