I am writing a parser and as a part of that, I have an Expander class that "expands" single complex statement into multiple simple statements. For example, it would expand this:
x = 2 + 3 * a into:
tmp1 = 3 * a x = 2 + tmp1 Now I'm thinking about how to test this class, specifically how to Arrange the tests. I could manually create the input syntax tree:
var input = new AssignStatement( new Variable("x"), new BinaryExpression( new Constant(2), BinaryOperator.Plus, new BinaryExpression(new Constant(3), BinaryOperator.Multiply, new Variable("a")))); Or I could write it as a string and parse it:
var input = new Parser().ParseStatement("x = 2 + 3 * a"); The second option is much simpler, shorter and readable. But it also introduces a denpendencydependency on Parser, which means that a bug in Parser could fail this test. So, the test would stop being a unit test of Expander, and I guess technically becomes an integration test of Parser and Expander.
My question is: is it okay to rely mostly (or completely) on this kind of integration teststest to test this Expander class?