Skip to main content
21 events
when toggle format what by license comment
Nov 3, 2022 at 0:00 history tweeted twitter.com/StackSoftEng/status/1587957843986186240
Nov 2, 2022 at 23:57 comment added gnasher729 Some languages have an attribute @Testable which allows unit tests to access things even when they are private. In C / C++ an absolute hack would be to have a macro #define private public that you use when compiling unit tests, which would make things public for unit tests without changing your source code. Of course everything must now be declared as either private or public, which isn't bad anyway.
Sep 6, 2015 at 12:37 comment added gnat see also: Testing private methods as protected
Aug 13, 2014 at 10:43 comment added Mike Nakis One more thing: being an assert whore is far more noble than the alternative, which is 'programming with reckless abandon'. Testing should in no way be seen as an excuse for limiting the use of assert. Taken to an extreme, assert is your real quality assurance mechanism, while testing is just a means of guaranteeing code coverage.
Dec 23, 2011 at 16:03 comment added Gilbert Le Blanc @David Thornley: Thanks for the reply. I'm used to Java where just about any complicated class has a toString method for visual inspection, and could have a toTesting method for exposing private variables.
Dec 22, 2011 at 21:59 comment added David Thornley @Gilbert Le Blanc: Because getters violate encapsulation also, unless what they get is meaningful in terms of the class. Your class API should all make sense for users of the class, and not be compromised for testing. (MikeNakis points out that you may want to put additional meaningful functions into the API.)
Dec 22, 2011 at 18:52 vote accept Zonko
Dec 22, 2011 at 17:33 comment added rlperez Precisely, it is a top language but most of the top languages are not Python and endorse setting appropriate scope. I stand by my statement. There are patterns designed to make highly testable software while ensuring variables maintain scope. Even Python programmers tend to emulate scope with prefixes from what I have seen.
Dec 22, 2011 at 16:59 history edited Zonko CC BY-SA 3.0
example
Dec 22, 2011 at 16:36 comment added Péter Török See also: stackoverflow.com/questions/3049122/…, stackoverflow.com/questions/2811141/…
Dec 22, 2011 at 16:34 answer added flamingpenguin timeline score: 8
Dec 22, 2011 at 16:26 comment added Mike Nakis "it is far from best practices in the majority of the top languages" does not logically imply (or even allude that) "Python is not a top language".
Dec 22, 2011 at 16:22 comment added S.Lott @Rig: Python's not a top language? Interesting.
Dec 22, 2011 at 16:19 answer added Mike Nakis timeline score: 41
Dec 22, 2011 at 16:11 comment added Gilbert Le Blanc Maybe I'm missing something, but why not write public getters for your private fields or methods?
Dec 22, 2011 at 15:58 answer added Alexander Galkin timeline score: 6
Dec 22, 2011 at 14:44 answer added Ant timeline score: 6
Dec 22, 2011 at 14:24 comment added rlperez Because that is far from best practices in the majority of the top languages. The real answer is to use good interfaces and such so you can use mock objects to perform testing against.
Dec 22, 2011 at 14:21 answer added Scott Whitlock timeline score: 14
Dec 22, 2011 at 14:15 comment added S.Lott The python folks only have public. They're happy. Why worry? Why not make everything public?
Dec 22, 2011 at 14:12 history asked Zonko CC BY-SA 3.0