Click here to Skip to main content
15,881,898 members
Home / Discussions / C#
   

C#

 
GeneralRe: How to programmatically paste text into a specific Word document Pin
Leif Simon Goodwin7-Feb-18 3:46
Leif Simon Goodwin7-Feb-18 3:46 
GeneralRe: How to programmatically paste text into a specific Word document Pin
Eddy Vluggen8-Feb-18 0:29
professionalEddy Vluggen8-Feb-18 0:29 
AnswerRe: How to programmatically paste text into a specific Word document Pin
Maciej Los6-Feb-18 5:28
mveMaciej Los6-Feb-18 5:28 
QuestionShould I unit test private methods? Pin
Hila Berger5-Feb-18 23:39
Hila Berger5-Feb-18 23:39 
AnswerRe: Should I unit test private methods? PinPopular
Pete O'Hanlon6-Feb-18 0:11
mvePete O'Hanlon6-Feb-18 0:11 
GeneralRe: Should I unit test private methods? Pin
OriginalGriff6-Feb-18 0:53
mveOriginalGriff6-Feb-18 0:53 
GeneralRe: Should I unit test private methods? Pin
Hila Berger7-Feb-18 0:24
Hila Berger7-Feb-18 0:24 
GeneralRe: Should I unit test private methods? Pin
Pete O'Hanlon7-Feb-18 1:05
mvePete O'Hanlon7-Feb-18 1:05 
Member 13624012 wrote:
Don't you think that testing only the public methods creates a problem?
No I don't.
Member 13624012 wrote:
When a test of a public method fails, it is not clear where it fails. Is it in the public method called directly by the test, or in a private method called by the public method?
Where it occurs is immaterial; the important thing is that the test failed. You have a predictable input (or set of inputs) going into a method that cause it to fail; debugging through the failure is a simple enough task that it doesn't matter.

To put things into perspective; if you have to debug private methods, you are introducing a coupling in that your test has to know how the methods behave and recreate the conditions necessary immediately before calling the method, so you need to take things like state into account. What you have done here is make it harder to change the working of code because any change will probably necessitate changing the tests as well. This is testing the "how" of the code. If you are testing public methods, you are more likely to be testing the behaviour of the code, so the inner logic has much more room to change.

An example might suffice here. Suppose I have a piece of code that writes to a log and returns a value to indicate that the log was successfully updated, and I have a test to ensure I get that value back; now, if I just test the public call of WriteToLog, I can ignore what happens inside and check the return value to ensure I get the expected one back - I'm ignoring the fact that, initially, I was logging to the file system (the how) and am now logging to a database. As long as I get that value back, I know that the particular piece of code behaved itself. This becomes much more important when you consider that I build up systems organically, so my initial internals would probably be a dummy logger which I would then build out and replace.
This space for rent

AnswerRe: Should I unit test private methods? Pin
Eddy Vluggen6-Feb-18 14:43
professionalEddy Vluggen6-Feb-18 14:43 
GeneralRe: Should I unit test private methods? Pin
Hila Berger6-Feb-18 23:58
Hila Berger6-Feb-18 23:58 
AnswerRe: Should I unit test private methods? Pin
GregoryPres7-Feb-18 22:14
GregoryPres7-Feb-18 22:14 
AnswerRe: Should I unit test private methods? Pin
Frygreen22-Feb-18 10:46
Frygreen22-Feb-18 10:46 
QuestionLinq Query Limitations, more than one query fails Pin
Member 136243255-Feb-18 10:47
Member 136243255-Feb-18 10:47 
AnswerRe: Linq Query Limitations, more than one query fails Pin
Dave Kreskowiak5-Feb-18 10:55
mveDave Kreskowiak5-Feb-18 10:55 
GeneralRe: Linq Query Limitations, more than one query fails Pin
Member 136243255-Feb-18 11:09
Member 136243255-Feb-18 11:09 
GeneralRe: Linq Query Limitations, more than one query fails Pin
Member 136243255-Feb-18 11:14
Member 136243255-Feb-18 11:14 
GeneralRe: Linq Query Limitations, more than one query fails Pin
Member 136243255-Feb-18 11:20
Member 136243255-Feb-18 11:20 
QuestionPreferred connection to database, config or class? Pin
bjay tiamsic4-Feb-18 12:46
bjay tiamsic4-Feb-18 12:46 
AnswerRe: Preferred connection to database, config or class? Pin
OriginalGriff4-Feb-18 19:59
mveOriginalGriff4-Feb-18 19:59 
GeneralRe: Preferred connection to database, config or class? Pin
bjay tiamsic5-Feb-18 19:48
bjay tiamsic5-Feb-18 19:48 
GeneralRe: Preferred connection to database, config or class? Pin
Pete O'Hanlon5-Feb-18 20:06
mvePete O'Hanlon5-Feb-18 20:06 
AnswerRe: Preferred connection to database, config or class? Pin
Eddy Vluggen5-Feb-18 1:18
professionalEddy Vluggen5-Feb-18 1:18 
QuestionPeak Search Algorithm with sliding window and peak excursion Pin
Krellon31-Jan-18 22:46
Krellon31-Jan-18 22:46 
AnswerRe: Peak Search Algorithm with sliding window and peak excursion Pin
Pete O'Hanlon31-Jan-18 22:49
mvePete O'Hanlon31-Jan-18 22:49 
GeneralRe: Peak Search Algorithm with sliding window and peak excursion Pin
Krellon31-Jan-18 23:13
Krellon31-Jan-18 23:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.