jsonizer icon indicating copy to clipboard operation
jsonizer copied to clipboard

Improve unit testing situation

Open rcorre opened this issue 10 years ago • 5 comments

Look in to using a proper unit-testing framework. At the very least, add descriptive messages to unit-test asserts.

rcorre avatar Mar 20 '15 11:03 rcorre

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 :)

SerialVelocity avatar Mar 22 '15 14:03 SerialVelocity

I was actually looking at dtest, which is apparently a wrapper around unit_threaded that allows it to automatically find your tests.

rcorre avatar Mar 22 '15 14:03 rcorre

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 dtest and generate the tests file (this is for a subproject)
  • Import the io module for unit_threaded and use scoped imports for unit_threaded.
  • Use scoped imports for std.stdio
  • Join with WriterThread on exit to fix an interaction bug between vibe.d and unit_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).

SerialVelocity avatar Mar 22 '15 14:03 SerialVelocity

Cool, thanks for posting this! I'd definitely prefer to keep using dub test than having to invoke dtest separately.

rcorre avatar Mar 22 '15 16:03 rcorre

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?

SerialVelocity avatar Mar 22 '15 16:03 SerialVelocity