28

This doc states the following:

If you happen to modify the public API of Angular, API golden files must be updated using...

Also this commit has the following heading:

fix: public API golden files #16414

I'm wondering what is usually referred to as "golden files". I've googled around and it seems that this phrase is commonly used.

  • https://lists.boost.org/boost-users/2013/04/78334.php. It's for some specific tests, where you compare the output of a test to a specific file. – Walfrat Oct 08 '17 at 10:23
  • 1
    In my neck of the woods, we refer to them as "baselines". When a test changes, or an implementation changes, we have to update the baselines to be in line with the new tests or implementations. – user1118321 Oct 12 '17 at 05:05

3 Answers3

42

A "golden file" is the expected output of some test (usually automated), stored as a separate file rather than as a string literal inside the test code. So when the test is executed, it will read in the file and compare it to the output produced by the system under test.

It's not really a very common expression; I have not heard it in 15 years of professional programming, even though I have used such files many times.

  • 1
    what is the common name to describe these files? – cowlinator Dec 10 '19 at 03:38
  • 2
    @cowlinator: I don't think there really is one. I just thought of them as "expected output". – Michael Borgwardt Dec 10 '19 at 07:28
  • 2
    A related term I'm familiar with is 'golden data'. This refers to test data that doesn't change. This input is expected to produce the same (or very similar output) when used in a regression test. The term 'golden' probably comes from the fact that gold is a stable substance. – JimmyJames Jan 29 '20 at 16:18
  • 4
    In electronics manufacturing, a 'golden unit' is the best prototype or one of the best/most typical units from the first production run that is set aside for verifying test procedures and for comparing with future units. – Jeanne Pindar Jan 30 '20 at 16:57
  • 1
    Honestly it is a fairly common expression for those working with Golang. It’s a pattern used in the Go standard library (as referenced here and here) – tdensmore Dec 10 '22 at 14:54
8

In a nutshell, a golden file is a file where we store the output and that will be used by the test as the expected output. This file should be updated any time the output changes for good reason. That's that simple :) .

Once again, introducing and using golden files in our tests is pretty straightforward and easy to use.

I got this useful link.

jefflunt
  • 793
  • 1
  • 6
  • 13
3

I think this is also known as "snapshot testing" in some contexts (if not all).

Some references:

  • 1
    Great that you introduce an other often used term for the concept of "golden files", this can help the asker to answer their question. Great that you provide some links with more information. I think you can improve your answer even more by a (brief) description of what "golden files"/"snapshot testing" is. Stack overflow is often the first result that pops-up in google and it would be great if people can immediatly learn from your answer what "golden files" are. It also helps when the linked sited change or go down. – Kasper van den Berg Oct 31 '22 at 00:54