notexOPENOverview
Notex/Languages/Storing Sample Test Data
05.09LESSON 09 OF 29 · 1 MIN READ

Storing Sample Test Data

Always free to read

As go test walks your source code tree, it uses the current package directory as the current working directory. If you want to use sample data to test functions in a package, create a subdirectory named testdata to hold your files. Go reserves this directory name as a place to hold test files. When reading from testdata, always use a relative file reference. Since go test changes the current working directory to the current package, each package accesses its own testdata via a relative file path.

Tip

The text package in the examples directory demonstrates how to use testdata.

Progress is saved on this device.
KEEP EXPLORING

One note leads to another.

Back to the library →
⌕
Search across the entire library ⌘ K