I am studying TDD and I have a question about private / protected variables. My question is: If the function I want to test works with a private variable, how can I test it?
Here is an example I'm working with:
I have a class called Tablethat contains an instance variable with a name internalRepresentationthat is a 2D array. I want to create a function called multiplyValuesByNthat multiplies all the values in a 2D array by an argument n.
So, I am writing a test for it (in Python):
def test_multiplyValuesByN (self):
t = Table(3, 3)
t.set(0, 0, 4)
t.multiplyValuesByN(3)
assertEqual(t.internalRepresentation, [[12, 0, 0], [0, 0, 0], [0, 0, 0]])
Now, if I make it internalRepresentationprivate or secure, this test will not work. How should I write a test, so it does not depend on internalRepresentation, but still checks that it looks correct after the call multiplyValuesByN?
source
share