The problem here is that \testtrue is not expandable and not protected and therefore fragile. It is defined as \let\iftrue\iftrue. In an expandable context like \edef or \typeout the \let assignment is ignored, and both if-switches are expanded. Because there is only one \fi (which is taken as part of \iftrue) the compiler complains about the missing \fi.
You can use \test{<true>}{<false>} in this context, but not \testtrue or \testfalse. So you would need to do the following:
\typeset{\test{True}{False}}
\testtrue
\typeset{\test{True}{False}}
I like to give you one more advice. I would define the \test macro as follows:
\makeatletter
\newcommand{\test}{%
\iftest
\expandafter\@firstoftwo
\else
\expandafter\@secondoftwo
\fi
}
\makeatother
This way the if-statement is fully processed before one of the two arguments is processed. This avoid some issues with can arise when code is used inside and if-switch. For example defining a new if-switch with \newif and using it inside such an argument will break, if that argument is to be skipped.
The \@firstoftwo and \@secondoftwo macros simply take two arguments and expand to either the first or the second. The \expandafter expands (i.e. removes, in this case) the \else or \fi first. Also note the % after the { which is required to avoid a space being added there by the line break.
\typeoutand not\typeset, right? – Werner Nov 22 '11 at 19:12minimalclass for minimal working examples (MWE). Despite the name it is not intended for that and can cause problems, because it does not define everything a real class does. Also a MWE should actually show what is not working, i.e. add the code which causes the trouble. – Martin Scharrer♦ Nov 22 '11 at 19:23articledoesn't do any harm either. It is better to be consistent and because the OP is new here I mentioned it, so that he doesn't start any bad habits. – Martin Scharrer♦ Nov 22 '11 at 19:54\global\testtrueoutside the\typeout. – egreg Nov 23 '11 at 22:46