Linked Questions

-1 votes
3 answers

Should methods with business logic be made private? [duplicate]

So I am writing a project using Spring Boot. All of my logic resides in @Service classes. I have separated each service class based on entity. For example - If I have two independent entities A and B, ...
rsp's user avatar
  • 143
299 votes
14 answers

How do you unit test private methods?

I am working on a java project. I am new to unit testing. What is the best way to unit test private methods in java classes?
Vinoth Kumar C M's user avatar
186 votes
10 answers

Why is Clean Code suggesting avoiding protected variables?

Clean Code suggests avoiding protected variables in the "Vertical Distance" section of the "Formatting" chapter: Concepts that are closely related should be kept vertically close to each other. ...
Matsemann's user avatar
  • 1,948
113 votes
14 answers

Should I avoid private methods if I perform TDD?

I'm just now learning TDD. It's my understanding that private methods are untestable and shouldn't be worried about because the public API will provide enough information for verifying an object's ...
pup's user avatar
  • 1,712
88 votes
11 answers

Is it a bad practice to modify code strictly for testing purposes

I have a debate with a programmer colleague about whether it is a good or bad practice to modify a working piece of code only to make it testable (via unit tests for example). My opinion is that it ...
liortal's user avatar
  • 1,175
40 votes
6 answers

Why is unit testing private methods considered as bad practice?

Context: I am currently working on a small project in Python. I commonly structure my classes with some public methods that are documented but mainly deal with the high level concepts (what a user of ...
Serge Ballesta's user avatar
35 votes
5 answers

Why is it often said that the test cases need to be made before we start coding? [duplicate]

Why is it often said that the test cases need to be made before we start coding? What are its pros and what the cons if we don't listen to this advice? Moreover, does that advice refer to black box ...
Aquarius_Girl's user avatar
30 votes
5 answers

Would you rather make private stuff internal/public for tests, or use some kind of hack like PrivateObject?

I am quite a beginner in code testing, and was an assert whore before. One thing worrying me in unit testing is that is often requires you to make public (or at least internal) fields that would have ...
Zonko's user avatar
  • 785
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
29 votes
3 answers

What happens with methods' tests when that method become private after re-design in TDD?

Let's say I start developing a role game with characters that attack other characters and that kind of stuff. Applying TDD, I make some test cases to test the logic inside Character.receiveAttack(...
Héctor's user avatar
  • 727
7 votes
4 answers

Sometimes private functions are simply yet-to-be-extracted internal units of functionality. So why not test them?

Sometimes private functions of a module or class are simply yet-to-be-extracted internal units of functionality, which might deserve their own tests. So why not test them? We will write tests for them ...
Aviv Cohn's user avatar
  • 21.3k
3 votes
4 answers

How do I deal with the fact that I am forced to make helper functions public for testing purposes?

I've encountered several scenarios that require me to mock certain helper methods because they call outside resources. As a result, I'm forced to convert all my helper methods from private into public....
JobHunter69's user avatar
1 vote
3 answers

Protected variable & protected method in the era of TDD [closed]

I understand protected method is good for unit testing since you can easily mock by the class by overriding the protected method for the sake of testing. However, protected variable is just a global ...
user34401's user avatar
  • 741
0 votes
1 answer

Unit testing protected methods which have no reason to be public

I need to make a sponsorship system with complex business requirements. Basically, after a user makes a payment, the system should get triggered. There are many different types of sponsoring, so I ...
Steve Chamaillard's user avatar
3 votes
3 answers

Should you indirectly test private methods from within public method tests?

It seems to be fairly common opinion that you should only test public methods for a class or module and not private methods. If private methods are doing their job correctly, then that should be ...
Jake Wilson's user avatar

15 30 50 per page