I am very new to TDD. I am reading TDD By Example and it says “never try to use the same constant to mean more than one thing” and it show an example of Plus() method.
In my opinion, there is no difference between Plus(1, 1) which uses same constant value and Plus(1, 2). I want to know what are pros and cons of using same constant value in test method?
I think you misinterprete that statement. What the author (imho) is trying to convey is that following code is a recipe for disaster.
You have two testcases reusing a none descriptive constant. There is no way to know that by changing
SomeRandomValueto0your testsuite will fail.A better naming would be something like
where it should be obvious as to what the constants are used for.You should not get to hung up on the idea of code reuse when creating testcases.
Or to put it in other words: