Search code examples
dartdirectory

Is there a "correct" folder where to place test resources in dart?


I have a simple dart class I am trying to test.
To test it I need to open a txt file, feed the content to an instance of the class and check that the output is correct.

Where do I place this txt file? The txt file is useless outside of testing.

Also, related, how do I acess its directory consistently? I tried placing it in the test folder, but the problem is that:

System.currentDirectory

Returns a different directory if I am running the test on its own or the script calling all the other test dart files on at a time


Solution

  • I check if System.currentDirectory is the directory containing the pubspec.yaml file, if not I move the current directory upwards until I found the directory containing the pubpsec.yaml file and then continue with the test code.