UnitTest and visual D

Jonathan M Davis jmdavisProg at gmx.com
Thu Feb 23 17:38:01 PST 2012


On Friday, February 24, 2012 02:11:50 Chris Pons wrote:
> I am following the book "The D Programming Language" and am at
> the portion about functions and unittest. For some reason I
> cannot get unittest to do anything noticeable.

If the unit tests pass, they don't print anything unless you add statements to 
them which do. You only get stuff being printed out on failure. This works 
particularly well for the command line (it's normal in Unix-land for stuff to 
print nothing on success unless them printing stuff out is their job - this 
makes it easier to pipe programs and the like). Some people complain about it 
from time to time, but that's the way it is. If you really want them to print 
something though, you can always add your own print statements.

If you compiled with -unittest, the unit tests run before main does, so if all 
of your tests pass, then your program will run normally after the unit tests 
have been run.

It's not uncommon for people to do something like this so that they can have 
the unit tests run without running their actual program:

version(unittest) void main() {}
else void main()
{
 //Your normal main...
}

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list