Search code examples
javaunit-testingtheory

Unit Testing - Theorem


So, I've seen a video about TDD, where the presenter said, that you should unit test only the part of the class, what is give something out for the external world. He mentioned this is good, since this approach makes sure the class is keeping the "contract", so it's delivery its duty, but you are free to refactor the logic behind it.

I'm a bit confused here guys,because I learned that unit test should NOT depend from the outter world. Okay, I understand this is not a dependency, but why not testing the inside logic? Any idea? Please feel free to add as an answer!


Solution

  • Exactly... you test what is outputting to the "outer world," not inputting from the outer world.

    The idea is, the more you test the internal steps your code takes to output the right result, the more your unit tests will unintentionally break when the implementation changes even though the final result is exactly correct. You only want unit tests complaining when the final result is wrong.