Linked Questions
14 questions linked to/from Should Private/Protected methods be under unit test?
4 votes
3 answers
299 views
TDD and Protected Methods [duplicate]
I am trying to learn TDD by creating a copy of an existing MVC app I have but I am creating a copy of it from scratch using TDD. In my existing app I have an Application_AuthenticateRequest method as ...
3261 votes
59 answers
1.3m views
How do I test a class that has private methods, fields or inner classes?
How do I use JUnit to test a class that has internal private methods, fields or nested classes? It seems bad to change the access modifier for a method just to be able to run a test.
425 votes
31 answers
173k views
Should I test private methods or only public ones? [closed]
I have read this post about how to test private methods. I usually do not test them, because I always thought it's faster to test only public methods that will be called from outside the object. Do ...
41 votes
5 answers
29k views
Unit under test: Impl or Interface?
Suppose I have interface and implementation class that implements it and I want to write unit-test for this. What should I test interface or Impl? Here is an example: public interface ...
5 votes
1 answer
3k views
Should internal classes be unit tested? [closed]
We are developing a new API at work. My colleague and I are having different opinion regarding whether internal classes should be unit tested or not. Points given by my colleague for not unit testing ...
8 votes
3 answers
685 views
How do unit tests change when a base class is driven out?
This is in part a followup to this question. I'm not sure the best way to ask this, so I'll try a short story to set the scene: Once upon a time, there was a class ‘A’, which had a unit test class ‘...
1 vote
3 answers
467 views
TDD duplicate assertions
The consensus seems to be not to test private methods when doing TDD. Should Private/Protected methods be under unit test? I keep hitting this same scenario. I have a private method (as an example ...
2 votes
2 answers
1k views
Unit testing a overridden protected method from a class that does not have default constructors
I have a class like this: Notice it does not have a default constructor either and inherits from some other class public class IdentifierManager : IdentifierManagerBase { public IdentifierManager(...
2 votes
1 answer
977 views
AngularJS unit test controller with only private functions
I have following controller that has only private functions. I am struggling to test this controller. Shall I test if it is doing $emit, since the ImageService has been tested? How do I test $emit in ...
0 votes
2 answers
844 views
Calling non default constructor of tested class from test class
I'm new to unit testing and I'd like to know how is this, I guess typical, problem usually solved: I have protected method that I'd like to test. I've overriden the tested class with the test class, ...
3 votes
1 answer
924 views
Unit testing an alias method
What would be the best practice for unit testing a method that only calls 2 other methods and no logic? internal ICollection<ObjA> FunctionA() { IEnumerable<ObjB> b = _factory....
0 votes
1 answer
300 views
Private accessor won't access private member
In my class, to test, I have a private boolean instance variable and a method to access it: MyClass() { private volatile bool b; public MyMethod() { b = false; } } After ...
1 vote
1 answer
120 views
Test private members on javascript
I've been working on a simple project on Adobe Extend Script Toolkit and is having trouble implementing tests on private members. I have come up with a solution which is to expose the privates inside ...
0 votes
1 answer
140 views
How to Unit Test a Protected Method with database connection inside a public method in C#?
I have the following scenario: public class Child : Parent { private int _eventTypeId; public override Dictionary<string, dynamic> Execute(IDynamicDatabaseConnection dbConn, IDbTransaction ...