How can I load this file into an NUnit Test?

后端 未结 4 1660
温柔的废话
温柔的废话 2020-12-23 19:19

I have the following IntegrationTest project structure ...

\"enter

If i wish t

4条回答
  •  悲&欢浪女
    2020-12-23 20:19

    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(TestContext.CurrentContext.TestDirectory + "\\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();
    }
    

提交回复
热议问题