1

Could not find this question so probably I'm missing something here.

I added Unit tests to my project (written via Intellij). I added some resources - files which are quite big (1.5 mb) which are the expected result of my tests. Its seems to me not reasonable to add them to the jar that i ship to the customer. Isnt there a way to exclude everything which is related to Junit from the jar that i build?

chenop
  • 4,743
  • 4
  • 41
  • 65
  • The answer is almost certainly yes, but the specifics will depend upon how are you building your JAR. Can you provide more details? – Duncan Jones Apr 22 '14 at 07:30

3 Answers3

1

No, you should not. One reason is that you have a bunch of libraries that you only use for testing, e.g. Mockito, jUnit. You do not want those in your production classpath. And of course size may matter, as you say 1,5MB for some test resources.

But you can nevertheless ship your test code. We bundle those unit tests and test resources in a test jar. So in the end we produce three jar files that might be shipped to a customer

  1. library.jar
  2. library-src.jar
  3. library-test.jar

There are several ways to do this, e.g.

Community
  • 1
  • 1
cheffe
  • 9,345
  • 2
  • 46
  • 57
0

Q: Should I exclude my JUnit tests from the .jar?

A: Yes, probably.

Q: Should I exclude my multi-MB test results from the .jar?

A: Yes - definitely!

Q: How do I do this?

A: One good approach is to use "ant", write a build.xml with a "jar" task, and add "exclude" clauses for the files you DON'T want in the .jar.

Here are some links:

FoggyDay
  • 11,962
  • 4
  • 34
  • 48
0

If you use maven for building your project, you can add the plugin maven-jar. It generates a test-jar that will contain your test classes. It's important that you put all your test classes under the src/test/java directory.

In this way you can have your junit separated from the other classes.

Alfredo Diaz
  • 628
  • 1
  • 6
  • 13