Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Include Unit tests in the same package as the source code in Java

I'm getting back into Java after a long stint in the Ruby world and I've got a question about JUnit tests and the source I'm testing.

If I've got a package of graphics code for my company, lets call it com.example.graphics, should I include my tests in that package too or should they be included in a seperate package, like com.example.graphics.test?

like image 308
TheDelChop Avatar asked May 24 '10 16:05

TheDelChop


2 Answers

In the same java package is fine. It's actually necessary if you need to access package-private classes, methods, or fields. However, the source should be logically separate:

src/main/com/example/graphics
src/test/com/example/graphics
like image 190
Brett Kail Avatar answered Sep 29 '22 11:09

Brett Kail


If you do not need to access private classes it is actually a question of flavor.

I sometimes even tend to create an additional test-project referenced to the product-project. Therefore, product and test are clearly seperated.

like image 43
Philipp Andre Avatar answered Sep 29 '22 11:09

Philipp Andre