我怎样才能加载此文件到一个NUnit测试? [英] How can I load this file into an NUnit Test?
本文介绍了我怎样才能加载此文件到一个NUnit测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下IntegrationTest项目结构...
I have the following IntegrationTest project structure ...
如果我想使用测试数据 126.txt
在 NUnit测试
,我怎么加载普通的txt文件的数据?
If i wish to use that test data 126.txt
in an NUnit Test
, how do I load that plain txt file data?
注:该文件是 - 连接 -
和我使用C#(由图像说明)。
NOTE: The file is -linked-
and I'm using c# (as noted by the image).
欢呼:)
推荐答案
您可以在属性指定文件被复制到输出文件夹和单元测试里面:
You could specify in the properties of the file to be copied to the output folder and inside the unit test:
string text = File.ReadAllText("TestData\\126.txt");
作为一种替代方法,你可以嵌入此文件作为一个资源进入测试组件,然后>
As an alternative you could embed this file as a resource into the test assembly and then:
var assembly = Assembly.GetExecutingAssembly();
using (var stream = assembly.GetManifestResourceStream("ProjectName.Tests.IntegrationTests.TestData.126.txt"))
using (var reader = new StreamReader(stream))
{
string text = reader.ReadToEnd();
}
这篇关于我怎样才能加载此文件到一个NUnit测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文