Private class unit tests

java, junit, private, unit-testing

Solution

Create the unit test class in the same package.

For example, If `com.example.MyPrivateClass` located in `src/main/java/com/example/MyPrivateClass.java`

Then the test class will be in same package `com.example.MyPrivateClassTestCase` and will be located in `src/test/java/com/example/MyPrivateClassTestCase.java`

Problem

How to unit test private (means with package visibility) classed in java? I have a package, only one class is public in this package, other classes are private. How to cover other classed with unit tests? I would like to include unit tests in resting jar.

Original source