Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Junit test cases of non public class

Tags:

java

I have a class as following

package a.b
public class Public_Class{
  public void add(){
    //logic
  }
}
class Non_Public_Class{
  public void subt(){
    //any logic
  }
}
package a.c

Now I want to make test cases of method subt() in "Non_Public_Class".

How can I access that non public class and my test cases are not in the same package?

like image 469
Mohit Nagpal Avatar asked Sep 15 '25 22:09

Mohit Nagpal


1 Answers

You should follow the now (more or less) standards for directory structures that tools like maven suggest. Meaning:

You can have

  • src/main/java ... and here go all your production code packages
  • src/test/java ... and here go all the test packages (which then can have the same names as your production packages)

That allows you to write unit test for "package protected" stuff.

like image 58
GhostCat Avatar answered Sep 17 '25 11:09

GhostCat