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?
Yes, it is doubtlessly an appropriate means of verification.
Yes, testing through the external interface of an object is ideal (vs hacking into its internals for verification). As long as each behavior is tested, you should not have any problem. If Enqueue depends on Size() and Size is already proved to be working as expected, you can safely write the test like you mention.
For this example, I probably start by implementing Size() [0 elements, queue created with 1, n elements]. Then move to Enqueue() and verify if Size is incremented by 1.
You're on the right track.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With