I am making some unit tests and I have a JSON file with some data in it. I am writing some unit tests that take that file and use that data as well.
So this data would be used live and for unit tests.
I don't want to maintain two copies if possible so I am wondering how can I reference this file?
Strictly speaking, unit tests should not use the file system because it is slow. However, readability is more important.
Unit tests run against specific lines of code. So it makes sense to place them right next to that code. Integration tests run against many lines of code in many files. There is no single place that would make sense, so it's best to have them in a /tests directory.
To run all the tests in a default group, choose the Run icon and then choose the group on the menu. Select the individual tests that you want to run, open the right-click menu for a selected test and then choose Run Selected Tests (or press Ctrl + R, T).
On the File menu, select New > Project, or press Ctrl+Shift+N. On the Create a new project page, type unit test into the search box. Select the project template for the test framework that you want to use, for example MSTest Test Project or NUnit Test Project, and then select Next.
I think that you are looking for the "Add as a Link" feature in the Visual Studio's Add
-> Existing Item...
dialog:
Then you need to set the "Copy to Output Directory" parameter for this file to any value from these:
I.e.
More details you can find in this MSDN article.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With