BDD confusion
Posted: Sat Dec 22, 2007 5:33 pm
From wikipedia: http://en.wikipedia.org/wiki/Behavior_d ... evelopment
The quoted statement above confuses me...especially "If calculated at all"
How else would the prime number object return results? It could use an internal lookup table I suppose and thus avoid calculating...but practically speaking...the object would likely calculate the values...which is what you would be interested in testing to ensure the algorithm worked as expected, is it not?
Inorder to test it's behavior...would this not require you to mock the PrimeNumber object? In which case it would return only what you told it to via expectOnce() and/or setReturnValue (assuming simpletest)???
What am I missing about that statement and the above code snippet? If the PrimeNumber object didn't calculate values...and it used a lookup table...the final assertion is still what you are testing - verifying the implement works as expected.
What was the authors intent with that statement (Not calculated at all)?
1) Was he suggesting it could use an alternative technique, such as a lookup?
2) Was he suggesting that the object be mocked and would return whatever you told it to via setReturnValue() because you are testing the behavior *not* the state?
If #2 is correct...and the PrimeNumber object was mocked and you told it to return a certain value and thus forced the assert to pass...what exactly are you testing? I see no behavioral testing happening there and the assert is obviously going to pass or fail...as you are basically passing the expected result indirectly to the assert via the mock object - make sense?
Cheers
First example:In the example above it's not really important how the prime numbers are calculated - if calculated at all. What's important is that the numbers are correct which is the expected behavior of the application.
Code: Select all
public class PrimeNumberCalculatorTests extends junit.framework.TestCase {
public void testIfPrimeAfter100() {
PrimeCalculator calculator = new EratosthenesPrimesCalculator(100);
int result = calculator.nextPrime();
assertEquals("First prime after 100 should be 101 but is " + result, 101, result);
}
}
How else would the prime number object return results? It could use an internal lookup table I suppose and thus avoid calculating...but practically speaking...the object would likely calculate the values...which is what you would be interested in testing to ensure the algorithm worked as expected, is it not?
Inorder to test it's behavior...would this not require you to mock the PrimeNumber object? In which case it would return only what you told it to via expectOnce() and/or setReturnValue (assuming simpletest)???
What am I missing about that statement and the above code snippet? If the PrimeNumber object didn't calculate values...and it used a lookup table...the final assertion is still what you are testing - verifying the implement works as expected.
What was the authors intent with that statement (Not calculated at all)?
1) Was he suggesting it could use an alternative technique, such as a lookup?
2) Was he suggesting that the object be mocked and would return whatever you told it to via setReturnValue() because you are testing the behavior *not* the state?
If #2 is correct...and the PrimeNumber object was mocked and you told it to return a certain value and thus forced the assert to pass...what exactly are you testing? I see no behavioral testing happening there and the assert is obviously going to pass or fail...as you are basically passing the expected result indirectly to the assert via the mock object - make sense?
Cheers