Skip to main content
typo; grammar
Source Link
svick
  • 10.2k
  • 1
  • 40
  • 54

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?

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 denpendency 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 tests to test this Expander class?

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 dependency 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 test to test this Expander class?

added integration-tests tag
Link
Jonathan Eunice
  • 9.8k
  • 1
  • 34
  • 42
Tweeted twitter.com/#!/StackProgrammer/status/540572035576233984
syntax highlighting
Source Link
svick
  • 10.2k
  • 1
  • 40
  • 54

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 
x = 2 + 3 * a 

into:

tmp1 = 3 * a x = 2 + tmp1 
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")))); 
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"); 
var input = new Parser().ParseStatement("x = 2 + 3 * a"); 

The second option is much simpler, shorter and readable. But it also introduces a denpendency 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 tests to test this Expander class?

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 denpendency 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 tests to test this Expander class?

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 denpendency 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 tests to test this Expander class?

Source Link
svick
  • 10.2k
  • 1
  • 40
  • 54
Loading