The common way is to make the private method protected or package-private and to put the unit test for this method in the same package as the class under test.
Guava has a @VisibleForTesting
annotation, but it’s only for documentation purposes.
More Related Contents:
- How do I test a class that has private methods, fields or inner classes?
- Conditionally ignoring tests in JUnit 4
- Difference between @Before, @BeforeClass, @BeforeEach and @BeforeAll
- Test class with a new() call in it with Mockito
- Assert equals between 2 Lists in Junit
- Mockito : how to verify method was called on an object created within a method?
- How to tell a Mockito mock object to return something different the next time it is called?
- Get name of currently executing test in JUnit 4
- How to test code dependent on environment variables using JUnit?
- Multiple RunWith Statements in jUnit
- How to run all tests belonging to a certain Category in JUnit 4
- How do I assert equality on two classes without an equals method?
- How to use JUnit to test asynchronous processes
- AssertEquals 2 Lists ignore order
- How to verify that a specific method was not called using Mockito?
- JUnit 4: Set up things in a test suite before tests are run (like a test’s @BeforeClass method, just for a test suite)
- How to test a Jersey REST web service?
- Injecting @Autowired private field during testing
- java.lang.NoClassDefFoundError in junit
- Why are my mocked methods not calld when executing a unit test?
- Forming Mockito “grammars”
- how to export (JUnit) test suite as executable jar
- Testing against Java EE 6 API
- How do I unit test jdbc code in java? [closed]
- How can I unit test void functions?
- Java verify void method calls n times with Mockito
- Does Junit reinitialize the class with each test method invocation?
- Junit Test of Setters and Getters of Instance Variables
- Why are my mocked methods not called when executing a unit test?
- How to test methods that call System.exit()?