I am trying to come up with a test case for a Queue class that I have not yet implemented. While trying to write the code for testEnqueue method I could not find ways to verify apart from using size() or dequeue().
Is it fine to to use other public methods(for ex: size/dequeue) to verify the test case for a public method(enqueue) of the same class?
As I understand you see a classical chicken and egg problem here – how can you test
a()and verify its behavior usingb()and then testb()by usinga(). From theoretical perspective if both of them are incorrect, the test might still pass… It’s like testing JUnit using JUnit.However if you treat your code as a black-box (which is the case when doing TDD) and you just write tests that give your class/unit some input and verify the output, there is nothing wrong with this approach. Just remember to test all the typical cases and corner cases/border conditions – if they match your business expectations, what could be wrong?