Linked Questions

30 votes
8 answers

Value of using private methods vs all public in classes for internal software for ease of unit testing [duplicate]

Here's a skeleton of a class I built that loops through and deduplicates data - it's in C# but the principles of the question aren't language specific. public static void DedupeFile(FileContents fc) {...
Bob Tway's user avatar
  • 3,616
27 votes
7 answers

Why did Java make package access default?

I'm asking this question because I believe they did it for a very good reason and that most people do not use it properly, well from my experience in industry so far anyway. But if my theory is true ...
newlogic's user avatar
  • 415
20 votes
3 answers

Designing unit tests for a stateful system

Background Test Driven Development was popularized after I already finished school and in the industry. I am trying to learn it, but some major things still escape me. TDD proponents say lots of ...
durron597's user avatar
  • 7,590
19 votes
5 answers

When to use interfaces (unit testing, IoC?)

I suspect I've made a schoolboy error here, and am looking for clarification. A lot of the classes in my solution (C#) - dare I say the majority - I've ended up writing a corresponding interface for. ...
Andrew Stephens's user avatar
10 votes
3 answers

Unit testing methods that call suppliers webservices

I have a class with one public method Send() and a few private methods. It calls a couple of webservices and processes the reponse. The processing is done in private methods. I want to unit test the ...
Tom Squires's user avatar
  • 17.7k
10 votes
1 answer

Testing private methods as protected

I was reading this answer about testing private methods and it mentioned several possibilities: extract methods as public to another class make them public separate the env of test and production ...
sam's user avatar
  • 211
4 votes
4 answers

Extending the class to test it: is this testing approach fine?

I am curious if the following example of testing a class with protected methods is fine. For example, say you have the following class Foo that has method a() of return type Bar: class Foo { ...
oneturkmen's user avatar
4 votes
2 answers

continuous integration impact on ticket sizing

I've been doing research on CI (continuous integration) and I can't find any info on the changes CI would introduce to ticket sizing. CI states developers should merge to the mainline every day (or ...
zero's user avatar
  • 143
3 votes
4 answers

What is the best practice for a regression test that wants to know about encapsulated information?

Suppose you have two classes: Alpha, and Bravo. Alpha constructs a new Bravo class during its own constructor and exposes no public visibility to it. Bravo has a String named charlie (and a method to ...
Wallace Brown's user avatar
3 votes
2 answers

Test Internals with TDD?

I'm new to TDD, and relatively new to software development in general (e.g. < 4 years experience), but I am trying to learn. I have been toying with TDD but ran into what I know realize is a ...
Adam Thompson's user avatar
3 votes
0 answers

How to properly test many methods when main logic is in private method [duplicate]

This is a little bit of follow up question to How to test private methods. I totally agree (and experienced what happens when you try) that we should not test private methods. Sometimes though it ...
Greg's user avatar
  • 425
2 votes
3 answers

How to not violate the single responsibility principle?

Let's say I'm writing a class that tracks a single stock ticker. In this simplified example, the StockTracker class holds a string that tells me the trend direction and a variable window that holds x ...
jgv115's user avatar
  • 139
1 vote
2 answers

Why is white box testing discouraged in OOP?

It seems the general consensus for unit testing classes is to test your object through its public interface only. So if you wanted to test the removeElement method on a LinkedList class you'd need to ...
user avatar
1 vote
1 answer

How to unit test public method which internally calls many internal or private methods which are already individually unit tested [duplicate]

In our ASP.NET Core application, we have many APIs which are calling public method from the service class. Service class is implementing an Interface. Each service method (depending upon complexity ...
WAQ's user avatar
  • 113
1 vote
1 answer

Testing a private method in Java [duplicate]

I am new writing good test cases, so please bear with me. Writing a test case for private methods public Stock getStock(String stockTicker) { Stock company = new Stock(); ...
Incpetor's user avatar
  • 127

15 30 50 per page