I'm new to Nunit3 and am currently using it to run some tests and want to read test data from a file rather than hardcoding it. The test data is used as the "expected" value and I want to read from a file because it is very large. Currently, reading from an absolute path works (ex: @"C:\path\to\TestData\testdata.txt"
). However, this is hardcoded into the MyTest.cs
test and I want it to be relative for testing on github actions or when testing on a different system. Is this possible?
I've tried to use things like "TestData\testdata.txt"
but the testing context is different than the context in the source directory I believe and I get file does not exist
errors. I have also tried to use Path.Combine()
with Path.GetDirectoryName(Assembly.GetEntryAssembly().Location
and System.Environment.CurrentDirectory
but the directory is not there because it doesn't get copied during the test build so the final path is incorrect.
Thanks!
TestAPI
|
-- src
-- API.Tests (this is a folder)
|
-- MyTest.cs
-- TestData
|
-- testdata.txt