user3474409
user3474409

Reputation: 55

My jar won't add my junit tests

The contents of my jar file does not contain my junit tests. I tried creating a main class that calls my tests with "Junit Core" but that too doesn't get added to my jar file. What am I missing?

Upvotes: 0

Views: 119

Answers (1)

Caffé
Caffé

Reputation: 1171

Your production package (your jar) is not supposed to contain the test code (your unit tests). Test code is supposed to be invoked only when the tests are been executed.

You shouldn't do it, but if you want the test code to be included in your package just put it in the same root folder of your production code. Ex: if you are using Maven, your folders structure might be something like this:

project_name/src/main/java/
    -> production code

project_name/src/test/java/
    -> test code

In that case, change it to:

project_name/src/main/java/
    -> production code
    -> test code

Be aware that doing that you will have some problems, like the tests not executing during a normal build. We might help you better if you put a question asking how to accomplish your goal (what is your goal?).

Update based on the goal explained in the comments: Would be better if this tool (Silk Central) could run your tests using Maven or Ant, and I'm pretty sure it can. I've been used different tools to run my Junit (or other XUnit frameworks) tests. What I do is to configure the tool to:

  • Get the source code from the version control.
  • Run the build/tests by calling Maven or Ant installed along the tool.
  • Read the Junit outputs.

Sometimes the tool has its own integration with Junit and you don't have even to use Maven or Ant.

I mean, your central build or tests tool should be able to run your tests just like you do in your own machine.

Take a look on this or search by "Silk Central junit" in the web:

http://community.microfocus.com/borland/test/silk_central/w/wiki/465.zero-maintenance-junit-testing-using-classpathsuite-in-sctm.aspx

Upvotes: 1

Related Questions