This seems to be due to rdmd ordering unit tests, which is not what I expected.
It seems that RDMD does not call unit tests for an instance of the template class, not at the time the instance was created, but instead right after the unit test completes, in which the class instance is completed.
Here's the MWE:
import std.stdio; class c1{ int c1func(int blah){ return blah; } unittest{ writeln("Testing c1 func."); stdout.flush(); } } class c2(T:c3) : c1{ private static int c2func(int blah){ return blah; } unittest{ writeln("Testing c2 func."); stdout.flush(); } int c2fun2(int blah){ T tmp = new T(); return tmp.c3fun(blah); } } class c3{ abstract int c3fun(int blah); } class c4 : c3{ override int c3fun(int blah){ return blah; } } unittest{ writeln("Testing class c1."); stdout.flush(); c1 myc2 = new c2!(c4)(); assert(1==0); }
In this case, the unit test will fail at the bottom (due to assert (1 == 0)), and so the unit class template tests will never be executed.
This poses a serious problem when using template classes along with unit tests. If your template class fails, somehow fails, which leads to the unit test where it was created to fail, then its own unit tests are never executed. In the event of a silent failure (in my code with errors in the template class, a silent exit was called), this will manifest itself, since the tests of the template class are never executed.
Summary : DMD usually just runs unit tests in the order in which they appear. However, since template classes do not exist without some completion of the template, unit tests within the template class do not run in the order in which they are displayed. Instead, they start (in order) immediately after the first unit test, where an instance of the template class is created.
Workaround : Adding a separate unit test directly below the template class that simply creates the instance, with all the types you want to test, will run the unit tests in the correct order. However, a seemingly more effective policy would be to run those unit tests in front of the test block in which the instance is created!