I have a class
class A {
List<int> a;
A() {
this.a = [];
}
void add(int x) {
a.append(x)
}
List<int> display() {
return a;
}
}
This is a simple class I want to write in a TDD approach. my question is how do you write the test for the display()
since the add()
need to be called to make the test useful.
And it feels wrong to test the function it needs to rely on the other function which requires testing.
How to we handle this?
display
can exist at all is that you already have test for it. So, if you already have a test for it, then why are you asking how to write a test for it? – Jörg W Mittag Dec 24 '20 at 12:40