linkrope / dunit

xUnit Testing Framework for D
Boost Software License 1.0
37 stars 9 forks source link

Having trouble running any tests #22

Closed vsajip closed 5 years ago

vsajip commented 5 years ago

It's probably something dumb I'm doing, so I'd appreciate any pointers - I'm fairly new to D and dub. Here's my dub.json:

{
  "name": "dconfig",
  "authors": [
    "Vinay Sajip"
  ],
  "description": "A test.",
  "dependencies": {
    "d-unit": "~>0.9.0"
  }
}

and here's my test code:

module tests;

import dunit;

class MyFirstTest {

    mixin UnitTest;

    @Test
    public void shouldFail()
    {
        string expected = "bar";
        string actual = "baz";

        assertEquals(expected, actual);
    }
}

When I run dub test, I get:

Generating test runner configuration 'dconfig-test-library' for 'library' (library).
Performing "unittest" build using /usr/bin/dmd for x86_64.
d-unit 0.9.0: target for configuration "library" is up to date.
dconfig ~master: building configuration "dconfig-test-library"...
Linking...
To force a rebuild of up-to-date targets, run again with --force.
Running ./dconfig-test-library 
All unit tests have been run successfully.

But nothing seems to run, since no failure is printed. The dconfig-test-library certainly seems to contain the symbols for MyFirstTest and shouldFail, so why would the test not be run?

The D version is DMD64 D Compiler v2.082.0, running on Ubuntu 16.04.

By the way, your example.d shows a mixin Main;, but I've omitted that since it doesn't seem to be needed to bring a main in. In fact, adding it causes a build failure due to Error: only one main allowed.

linkrope commented 5 years ago

You have to run unit_main from dunit.framework. There are, however, several ways to do this:

vsajip commented 5 years ago

Thanks. I figured it out and used the first option.