# MUnit unit tests for TraditionalForm formatting

I'm a strong proponent of unit tests and as such I'm using the MUnit framework from Wolfram Workbench on a regular basis. Many of the codes I'm working on also use TraditionalForm formatting in order to make objects look nicer in the Mathematica notebooks. Some of the formatting,, rules are pretty complicated which means that it would be nice to have unit tests for them as well.

However, I don't see a simple way to implement unit tests to check the TraditionalForm output of particular expression. For example, let us look at

MyObject/:MakeBoxes[MyObject[x_,y_],TraditionalForm]:=
If[x===y,SuperscriptBox["\[Alpha]",1],SuperscriptBox["\[Alpha]",2]]


Now I would like to write two tests like (pseudocode):

Representation[MyObject[1,1]] === SuperscriptBox[\[Alpha],1]
Representation[MyObject[1,2]] === SuperscriptBox[\[Alpha],2]


The best thing I was able to come up with is

TraditionalForm[MyObject[1,1]] === TraditionalForm[SuperscriptBox[\[Alpha],1]//DisplayForm]


Which however still doesn't return True. When I run Mathematica kernel without the frontend I see that both

TraditionalForm[MyObject[1,1]]


and

TraditionalForm[SuperscriptBox[\[Alpha],1]//DisplayForm]


evaluate to

//TraditionalForm= α^1


but for some reason Mathematica doesn't consider them to be equal.

Is there some handy function to output the TraditionalForm of MyObject[1,1] and MyObject[1,2] in terms of SuperscriptBox and \[Alpha]?

Or may be there is some standard way to write unit tests for the TraditionalForm representation that I'm completely missing?

TraditionalForm and DisplayForm are just "wrappers". If you look at FullForm of expressions compared in question, you'll see that although they look the same, internally they are represented differently:

MyObject /: MakeBoxes[MyObject[x_, y_], TraditionalForm] :=
If[x === y, SuperscriptBox["α", 1], SuperscriptBox["α", 2]]

(*
α^1
Out[4]//FullForm=
*)

TraditionalForm[SuperscriptBox["α", 1] // DisplayForm] // FullForm
(*
α^1
Out[6]//FullForm=
*)


If you want to compare box representation of expressions, you should explicitly convert them to boxes.

MakeBoxes[MyObject[1, 1], TraditionalForm] === SuperscriptBox["α", 1]
(* True *)