Package function to update testing “golden files”

Hello all! I have a package where I have some “golden files” that I use as references in my test suite. I’m trying to add a function to update all of the golden files, for developers to use whenever something like an external dependency or API changes.

So my question: is there a standard place to put a function like this in an R package? This article describes doing it in a Go package, by using flag to ‘go test’, but I'm pretty sure that's not a good approach for R.

Someone threw out the idea of keeping the script in ‘raw-data’ which might work. Any other ideas? Someone else mentioned putting it in ‘inst/script’ and then including that folder in .Rbuildignore since it is only a dev function, not user-facing.

To reiterate, this is a script that would be run manually by developers when something in the code changed and the test data needed to be updated. It is not actually part of the test suite.

I’ve looked around a bit and can’t seem to find a recommended pattern for this. Any thoughts or ideas are welcome.

1 Like

I am not sure I 100% understand what your golden files are but if they are reference outputs, your question is very timely as testthat dev version gained support for snapshot testing (and I watched the corresponding webinar two days ago!).

Vignette on snapshotting.

To update the snapshots, you run the tests and since the output will be different, you'll be told to run snapshot_accept() or snapshot_review().

Now if your question is about some sort of input for your tests, my answer is completely off topic.

1 Like

This topic was automatically closed after 45 days. New replies are no longer allowed.


If you have a query related to it or one of the replies, start a new topic and refer back with a link.