jsonizer
jsonizer copied to clipboard
Improve unit testing situation
Look in to using a proper unit-testing framework. At the very least, add descriptive messages to unit-test asserts.
I've started using unit_threaded after looking at them all. It requires a slight dub.json hack to make it work but I preferred its syntax over the others. Let me know which you like more :)
I was actually looking at dtest, which is apparently a wrapper around unit_threaded that allows it to automatically find your tests.
Yes, I tried using that. I didn't like that I had to invoke dtest instead of overriding dub test. So, I actually use dtest inside my dub.json. It is a bit hacky but I required some fixes that aren't available in the latest unit_threaded release (or develop):
"configurations": [
{
"name": "library",
},
{
"name": "unittest",
"targetType": "executable",
"mainSourceFile": "unit_threaded_tests.d",
"importPaths": [
".",
],
"sourcePaths": [
".",
],
"preGenerateCommands": [
"cd $PACKAGE_DIR && dub run dtest --quiet -- -f unit_threaded_tests.d > /dev/null",
"cd $PACKAGE_DIR && sed -i.bak 's/import unit_threaded.runner;/import unit_threaded.io : WriterThread; import unit_threaded.runner : runTests;/' unit_threaded_tests.d",
"cd $PACKAGE_DIR && sed -i.bak 's/import std.stdio;/import std.stdio : writeln;/' unit_threaded_tests.d",
"cd $PACKAGE_DIR && sed -i.bak 's/\\(int main(string\\[\\] args) {\\)/\\1 scope(exit) WriterThread.get.join();/' unit_threaded_tests.d",
],
"versions": [
"VibeCustomMain"
],
},
],
The preGenerateCommands do the following:
- Run
dtestand generate the tests file (this is for a subproject) - Import the
iomodule forunit_threadedand use scoped imports forunit_threaded. - Use scoped imports for
std.stdio - Join with
WriterThreadon exit to fix an interaction bug betweenvibe.dandunit_threaded.
The scoped imports are for dscanner. I have yet to make that run through dub though (try dub fetch dscanner && dub run dscanner if you want to know why).
Cool, thanks for posting this! I'd definitely prefer to keep using dub test than having to invoke dtest separately.
Note: I didn't put dub fetch dtest in there for multiple reasons:
- It's slow
- If you have no internet connection it breaks
- Why try and get it over and over?