TDD means a test first : you must update your code before changing the code. In this case, if you decide to add extra
, you should add tests for the API around extra
(until you have them, but maybe you want getExtra()
, etc.), and then, as you add and revise the tests, you notice that you need to add calls to setExtra()
and getExtra()
to testCopyFrom()
.
At this point, your tests will in most cases fail ( red ), and then you can make real code to pass them ( green ), and finally clear up and refactor , using your tests as a guide on what you broke something.
More about red-green-refactor is TDD.
In addition, you should mark getGrade()
as const
, i.e.
int getGrade() const { return grade; }
This means that you can use the const
pointer or a reference to an instance of MyClass
to get an estimate.
source share