UnnecessaryStubbingException During Tests

The full build is failing with this error, which essentially relates to the structure of tests file and requires a modification of the tests file. Is it a part of this module to rectify the test files as well? Or is it due to some other reason?

Please read the instructions carefully in the files provided.
Something related to creating an instance. Please check.

Hey have you added anything extra in the Portfolio Manager Test File apart from what’s already given?
Check again.

No, I have not added anything extra. I have been facing this issue since the first build in Module 4 but I assumed it would be resolved later since I had not completed all milestones.

There are two TODOs in PortfolioManagerImpl.java.
One at calculateAnnualizedReturn and another at getStockQuote Have you implemented both the functions?
You are supposed to use getStockQuote function inside calculateAnnualizedReturn function. are you doing that?

Its for the sake of clean code.

Please read the TODO’s carefully you have to exactly do the same which you did in module 3. But using pre-existing templates/codes/functions/partially written functions.

And use debugger when you are building the test. Put breakpoints in lines where you think error may occur.

Yeah I did do that. The error did not lie in not using the pre-written templates.

Yeah, I am well aware of that. Thank you so much :slight_smile:

Thank you. I found the bug. This was indeed useful.

What did you understand? Can you elaborate the same for others?

I accidentally ignored the 3 line stub for getStockQuote. Since there was no mention in the milestone or TODOs explicitly about the same, I didn’t realize that until you pointed it out. The stubs did say to refactor the code into two parts but out of which the first part talked about using BuildUri method. I assumed there was a minor typo, since I couldn’t find #2 there like #1 for BuildUri. That’s the reason the test for the exception because the method I had missed was being tested and since it wasn’t doing anything, the code in test file pertaining to it was being flagged as unnecessary stub.

1 Like