Hacker News new | past | comments | ask | show | jobs | submit login

I'm fond of taking this a step further and actually offloading the test cases to a separate language-agnostic file, then have implementations' test harnesses read cases from that file. The Ruby gem for Base32H¹ does exactly this to test the encoder/decoder logic, pulling the test cases from CSV files in a separate repo² included as a Git submodule. One of these days I need to port the other reference implementations over to using the tests repo, but once that's done I'll be able to update the test cases in one place and they'll automatically work everywhere.

----

¹ https://github.com/Base32H/base32h.rb/tree/master/spec

² https://github.com/Base32H/base32h-tests




What do you gain from having a separate language agnostic file?

If you are going to have a table, it seems to make sense to have the table next to the code that's using it. (Though I prefer property based testing.)


> What do you gain from having a separate language agnostic file?

Right now, nothing.

In the future, when I overcome my laziness, it's a single place to define tests that multiple projects in multiple languages (in this case, encoding/decoding libraries) need to pass in an identical manner. If I ever identify more edge cases that I need to test, I can add them in one place and all existing implementations would automatically test them, and for future implementations I only need to implement enough to read and loop through the test files and then I'm done.

Another advantage comes about in the corporate world (where most of my programming energy has less-than-fortunately gone): having test cases defined in a format like CSV that Excel can edit makes it easier for non-programmers (i.e. the vast majority of stakeholders for the average corporate software project) to read and write the test cases.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: