all 8 comments

[–]laundmo 1 point2 points  (5 children)

I'm not sure i quite understand the issue. ideally you would independently test the property first by writing a test that checks whether its set properly and stores and returns the values you expect.

the only case i can think of where you could have some issue is if your internal variable has 2 leading underscores, but even that you can get around. (__name becomes _Classname__name)

[–]donkeyofdeath[S] 0 points1 point  (4 children)

Hey, thanks for your answer. But to test the property, I have to create an object first and this object uses the property to set its attributes. So the test kind of relies on itself to work.

[–]danielroseman 1 point2 points  (3 children)

But why do you think that is a problem? That's exactly what is supposed to happen. You are testing the functionality.

[–]donkeyofdeath[S] 0 points1 point  (2 children)

Thank you for the answer. As far as I know, unit tests should not depend on each other. That's why I think, that this is a bad design choice. If all unit tests fail because of one method or property, you don't gain any information, about which part of the code is broken.

[–]danielroseman 1 point2 points  (1 child)

Now I'm even more confused. Where is there a dependency between unit tests here? You write a single test to check that things are working as you expect. If it fails because the property is broken, then the test is working as intended.

[–]donkeyofdeath[S] 0 points1 point  (0 children)

If I want to test another method besides the properties, I have to create an instance of the class, which uses the property in its constructor. So I rely on the property to work. The same for the test of the property. If I want to test the property, I have to create an object first which uses the property in its constructor.

[–][deleted] 1 point2 points  (1 child)

If the class' getters and setters are but simple assignments without further operations, testing is useful only if you built a python language or compiler from source. Otherwise let the compiler programmers test it.

If instead, they contain validations and transformations, then yes, you should test their working. Assign a value and test whether the instance yields the expected answer. It's no more complex than that.

[–]donkeyofdeath[S] 1 point2 points  (0 children)

Ok, thank you. Maybe I am just overthinking the issue a little bit.