[TIP] testing designing with "hidden" attributes

James Cooke me at jamescooke.info
Tue Jul 17 03:13:58 PDT 2018


Hi Alceu,

My opinion is that tests are to assist the developer (I agree with Daniel) - they are not executed at run time. Therefore, if a test will help you to prove / understand / validate any part of your code, they why not use it? If you want to test a "private" attr and it will help you, then why not? If something bad happens, then you can delete the test after or refactor it to fit some new code / requirement.

Harry put it much better here: https://www.obeythetestinggoat.com/book/chapter_philosophy_and_refactoring.html#_programming_is_like_pulling_a_bucket_of_water_up_from_a_well

My guess is that when you add tests to that code, that they will shine the light on an improved API / design. I find that happens especially as I DRY my test / app code (something I got from Kent Beck) and also when I work on encapsulation (something I got from Sandi Metz https://www.youtube.com/watch?v=OMPfEXIlTVE)

Hope that's helpful,

James



On Mon, 16 Jul 2018, at 8:25 PM, Daniel Knüttel wrote:
> Hi Alceu,
> 
> I think one should not design his classes for testing purposes
> (well obviously unless the classes are for testing). So you should
> design your classes the way they fit the intended purpose and later you
>  have to adapt your tests.
> 
> Do not forget: tests are there to check that the stuff you write works
> as you want it to work. In particular it might be useful to know that
> the attributes are hidden successfully.
> 
> I hope this helps.
> 
> Yours
> -- 
> Daniel Knüttel <daniel.knuettel at daknuett.eu>
> 
> _______________________________________________
> testing-in-python mailing list
> testing-in-python at lists.idyll.org
> http://lists.idyll.org/listinfo/testing-in-python



More information about the testing-in-python mailing list