Fork me on GitHub

Does anyone mix unit tests in the same file that they are testing? As opposed to creating a separate test file?


I'm wondering if clojure.test and test.check would be useful mixed in?


Prior to clojure I worked a lot in Python and always put my unit tests in separate files, but I'm open to change.


Or maybe I want to get in the habit of writing a few tests in the same file as I'm doing the development, because its easy, and then later moving those tests out into their own file so they don't clutter up the main module.


So my question is as much about workflow as it is about where the tests should ultimately end up.


I'm fairly new to clojure and so far I haven't written very many tests and I'm thinking that now is the time to start making the writing of tests part of my process.


Devcards, among its many other features, makes a good test runner.


pkobrien: I don’t - keep them completely separate.


Not really sure why I’d want to mix them up. I aim to have the smallest file delta possible. If you mix tests and functionality on the same file, you’d end up having to wade through file diffs where only the test changed.


@ricardo: Right, that's my usual approach with tests.


But some code I was working on recently got me thinking that it might not be bad to through a few tests right into the mix. Partly as tests, but partly as sort of documentation/example/literate programming


This is not a new idea by any stretch of the imagination, its just something I've always rejected in the past.


@sdegutis: it depends on the kind of system... But I usually like to start the full system (probably a component/system-map, the same that will be use in production but with config for testing) in every test, and stress it from different angles as a whole... I want to have some of those tests at the very least, apart from tests for specific components or groups of components, so I can be sure the "real system" is being tested...


But that's too broad, were you thinking on a specific kind of system or tests?