In a typical Julia package, tests are separated from the source files leading, I’d argue, to the omission of tests and a slower development cycle.
I would rather include function tests in the same file and adjacent to the definitions, for several reasons:
-
decreased conceptual distance, in that similar things should be near each other, much as single-file components are a useful thing in Vue.
-
faster development: when tests are in the same module as the definitions, the entire module can be replaced and a running REPL re-used, whereas when tests are in another or global module the source module cannot be replaced and the running REPL must be restarted. (A perhaps needed conversation for another topic is naming the various possible package development workflows and their steps.)
-
less duplication with Documenter strings: I find that at least some of my function examples are nearly identical to their unit tests. Moreover, unit tests demonstrate the uses and expectations that are at the root of api documentation.
I don’t know if other languages employ approaches like this, Vue’s single-file-components is all that came to mind.
I included “style” in the title because it is certainly possible to define tests in source files and call them right now, but this could be improved with some specific support from or extension to Documenter and Test.
But at the extreme, I might make a doc/function/test/end design, giving first-rate importance to both documentation and unit testing. I realize that this would be a big addition, but as useful as macros are I think documentation and test are more than decorations and that relegating them decreases usage and incorporation in tools. Of course I won’t be surprised if this ship has sailed.
I’d appreciate comments and links to other discussions on this,
Thanks!