9 replies
March 2016

disqus_CqgrdSEDct

That's a great tip. I've never considered adding a main method to one of my tests. Seems obvious after reading this.

1 reply
March 2016

verdammelt

Good idea. Team I was on a couple years ago had this exact problem... and a gold-master file *was* overwritten - didn't notice for a while unfortunately.

1 reply
March 2016

ashokbakthavathsalam

And from where, when and how would you call the main() function?

1 reply
March 2016 ▶ ashokbakthavathsalam

jbrains

I would only run main() when I wanted to generate a new Golden Master. The most common case involves the output changing (a test run fails) and then deciding that the new output is OK. (This is generally how to use Golden Master.)

Since I don't do this often, I don't need to make this part of any automated build or test run.

I have another article here that explains the Golden Master technique in more detail. http://blog.thecodewhispere...

Finally, I built this main() so that it didn't even need a command line argument, so you run it like any other command line application, either from a shell or using the Run command in your favorite IDE.

1 reply
March 2016 ▶ disqus_CqgrdSEDct

jbrains

I know. I felt the same way when I first saw it. It's funny how we limit our own thinking.

March 2016 ▶ verdammelt

jbrains

A key reason to commit the golden master to version control. When it changes, you notice.

March 2016 ▶ jbrains

ashokbakthavathsalam

Thanks much JB!

March 2016

declan_whelan

Another approach would be to use approval tests: https://github.com/approval...

1 reply
March 2016 ▶ declan_whelan

jbrains

Yes. I like the general mechanism of Approval Tests, although I very slightly prefer "generate golden master" and "run the test" as separate activities with different ways to launch. (Just an expression of my desire for control, I guess.) I imagine the difference is so small that I would get quite comfortable with both ways of thinking about it. (If a file named X happens to be there, then we know the expected result, and if not, then we don't and the test can't pass.)