Timeline for Why do Unit Testing Attributes usually require public Methods?
Current License: CC BY-SA 3.0
19 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Jun 29, 2018 at 10:17 | answer | added | Phill W. | timeline score: 2 | |
| Jun 28, 2018 at 18:59 | review | Close votes | |||
| Jul 4, 2018 at 3:05 | |||||
| Jun 28, 2018 at 18:47 | comment | added | Justin Dearing | @GregBurghardt This behavior is found in Nunit, and probably other test frameworks Microsoft didn't write. Sure in the years since asking this question I understand a lot more about .NET, but I still think its a fair question, and there is some good discussion in the comments. | |
| Jun 28, 2018 at 18:44 | comment | added | Greg Burghardt | I'm voting to close this question as off-topic because only Microsoft can answer this question. | |
| Jun 28, 2018 at 18:11 | history | bumped | CommunityBot | This question has answers that may be good or bad; the system has marked it active so that they can be reviewed. | |
| Mar 9, 2018 at 10:10 | answer | added | Vetle | timeline score: 0 | |
| Aug 28, 2015 at 11:15 | history | tweeted | twitter.com/#!/StackProgrammer/status/637221971642687488 | ||
| Aug 14, 2015 at 13:18 | comment | added | gnat | @FrankHileman if it's modern to spare developers from any means of restricting reflection to access code that is not intended to be accessible, it would be probably safer to stay in the past | |
| Aug 13, 2015 at 20:34 | comment | added | Frank Hileman | I don't think it is any more difficult to access private members via reflection, which is used anyway to look up the test classes and members. Perhaps it is a historical restriction based on past problems. | |
| Aug 13, 2015 at 12:11 | history | protected | gnat | ||
| Aug 12, 2015 at 13:58 | comment | added | gnat | you need to take in account that this design decision was made for a general purpose framework targeted for wide usage. In cases like that it's just safer for designer to assume and prepare to the worst. If it was, I don't know, some company-internal framework (where one can have chance to guarantee desired security policies), or if it was some tool of narrow, specialized purpose (think "viewer for inaccessible members"), designer would have other options to consider | |
| Aug 12, 2015 at 13:54 | comment | added | Justin Dearing | @gnat Well ok I could see a use case for a unit test running being launched in a locked down appdomain. Then again, that would be a problem if I was unit testing code that used reflection. | |
| Aug 12, 2015 at 13:12 | review | Close votes | |||
| Aug 12, 2015 at 22:12 | |||||
| Aug 11, 2015 at 21:50 | comment | added | gnat | ...hey, in .Net invoking members that are inaccessible according to the accessibility rules also involves messing with security / permissions. If I was a framework designer, I'd guess that my future users would be less unhappy to live with requirement of public methods than with one to take care of permissions | |
| Aug 11, 2015 at 21:12 | comment | added | gnat |
@RobertHarvey in Java, reason for similar restriction (eg in JUnit) is that framework designers don't want to mess with setAccessible which can be blocked by some custom SecurityManager
|
|
| Aug 11, 2015 at 20:41 | comment | added | Robert Harvey | @JustinDearing: Are you talking about making the test methods public, or making the methods under test public? Making test methods public is not controversial; it's easier for the Test Runner to run them that way. Put your test methods in another assembly if you don't want them to be part of the assembly under test's public API. | |
| Aug 11, 2015 at 19:59 | comment | added | jtiger | I don't think he's talking about testing his classes, he's talking about the actual test methods that are called by test framework. | |
| Aug 11, 2015 at 15:03 | comment | added | Robert Harvey | That's a really good question. The only good argument I've heard is that it follows the principle "program to an interface, not to an implementation," part of the SOLID principles. | |
| Aug 11, 2015 at 14:23 | history | asked | Justin Dearing | CC BY-SA 3.0 |