Why is my Base test failing?

Modified on Tue, 28 Mar, 2023 at 4:39 PM

Do you understand the error?

Base tests fail if our code is not checking for all the different inputs that need to be handled.

Where is the error occurring?

Error is in the logic of the code, can we re-read the problem statement and check if all the possible input cases are covered?

Why do you think you are seeing this error? What might be causing it?:

Can we unlock the failing test case and run it, this will help us understand what is the input, expected output and actual output for the failing test case. We can dry run on this if needed to find the issue with the logic in our code.

How to Debug this? To debug this issue, I would recommend the following steps:

To avoid this, it is recommended that you write a few test cases even before you start writing the code. This will help you write most of the logic initially so major changes need not be done after hitting the submit button. Even if you have already written the code, the same steps need to be followed to find and fix the issue.

write test cases that exercise the base cases that you have identified. These test cases should include a variety of different scenarios, both expected and unexpected, to test the full range of your code's capabilities. 

For example, let's say we are asked to capitalize the first character of every word in a string, and there are no special characters in the string, we can write test cases like below initially to test:

  1. learn by doing

  2. learn By Doing

  3. Learn by       doing

  4. LEARN BY DOING

  5. learn      by      doing

Now once we find where the logic is failing, we can update our code so our code passes these test cases.

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article