Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should utility test classes in a library go under test or main?

E.g. I have a file ConnectionDummy in Maven project Common. It is used only by tests in Email-Lib, Scanner and Common. Note Common itself also includes unit tests, but these files are just helpers to unit tests. Should it go Common's test or main?

Maven setting but I think this is probably common to many technologies.

like image 763
djechlin Avatar asked Oct 28 '25 05:10

djechlin


1 Answers

It depends a little bit on how strong you feel about having test (utility) code in your production system, down the road. Is code that's just sitting there, doing nothing, bad for your production environment? Imagine that your test utility has nifty annotations that e.g. Spring picks up during run-time?

I've come across people who don't care. Personally I feel strong about it, and don't want test code in my production environments. If that's your thinking too, there's two ways to go with Maven that I've seen in our projects:

  1. The test utility code goes in Common's test folder. You'll end up building test JARs (test-jar) for your Common project and you may run into transitive dependency issues where any <scope>test</scope> dependencies of your Common project that are needed by your test utility code are not going to be there when someone depends on your test JAR. This is a potential dependency nightmare where I've seen the "including project" re-defining a whole lot of dependencies that were already nicely defined by the "included project", but weren't picked up by Maven for being transitive at scope test.

  2. The test utility code goes in a separate test project, e.g. CommonTest which produces jar, not test-jar packaging. That way the test utility becomes "utility" to not only your dependent projects, but to the original Common project itself, just the same. By doing so, your test folder becomes truly an internal matter of a project. Maybe that's how the Maven guys have meant it, why else would making a test-jar not be a standard option? :)

like image 138
Sander Verhagen Avatar answered Oct 30 '25 08:10

Sander Verhagen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!