UnitTest and visual D

Chris Pons cmpons at gmail.com
Thu Feb 23 18:12:08 PST 2012


Ok, thanks.

I haven't run into version(...) yet. Would I be correct if I 
assumed that this version of void main: void main() {} would only 
run if -unittest was in the command line?

Also, what should be in a unit test? Test cases to make sure 
certain functions/classes are working as you intend them to?


> 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