This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 51544 - Target to create JAR of unit test classes
Summary: Target to create JAR of unit test classes
Status: NEW
Alias: None
Product: java
Classification: Unclassified
Component: Project (show other bugs)
Version: 4.x
Hardware: All All
: P3 blocker with 2 votes (vote)
Assignee: Tomas Zezula
: 50621 (view as bug list)
Depends on:
Reported: 2004-11-16 08:53 UTC by leomekenkamp
Modified: 2014-07-16 22:52 UTC (History)
2 users (show)

See Also:
Exception Reporter:


Note You need to log in before you can comment on or make changes to this bug.
Description leomekenkamp 2004-11-16 08:53:48 UTC
If a project A defines an interface IA then it is
logical for that project to also define an
(abstract) test class/testcase (TA) for that
interface with a factory method for creating
instances that need to be tested. If project B has
a class (CB) that implements interface IA, it
could then create a test TB by simply extending TA
and implementing the factory method.

Since there are no options to generate a jar
containing all test classes/testcases, there is
currently no portable (automatic) way to reuse
tests across projects. (including the build/test
directory is not portable imho)

Enhancement request: add functionality to create a
jar containing all test code so that test code can
be reused in other projects.
Comment 1 Jesse Glick 2004-11-29 21:20:55 UTC
Just include ${A}/build/test/classes/ in the test compilation
classpath for B. It should work AFAIK. I'm not sure what your meaning
of "portable" is.
Comment 2 leomekenkamp 2004-11-29 21:31:11 UTC
'Portable' as in 'usable in another IDE'. If I could give a jar
containing tests to an Eclipse using developer, he/she can extend the
(test)classes in that jar. One can add this to the build script
manually, but that does not 'feel' right to me. Having the test code
in the production code jar is a big no-no in my book.
Comment 3 Jesse Glick 2004-12-01 17:57:18 UTC
Obviously you would not put test classes into the production JAR.

Could be useful to have a separate test JAR target in a few
situations. But you can already add a target to build.xml, e.g.

<target name="jar-tests" depends="compile-test">
    <jar jarfile="dist/tests.jar">
        <fileset dir="${build.test.classes.dir}"/>

and you are done. Not sure why this doesn't "feel" right to you, other
than the obvious fact that it takes an extra thirty seconds or so, and
it is a little more cumbersome to run the target, though you can fix
that by adding e.g.

<target name="-post-jar" depends="jar-tests"/>

so that Build makes the test JAR too.

For that matter, people using other IDEs can also compile against
unJARred test base classes, I presume.

Main interesting enhancement in NB IDE would be to export this JAR as
an artifact so you could choose to use it from the Add Project...
dialog in a dependent project's test classpath. No immediate plans to
implement however.
Comment 4 leomekenkamp 2004-12-01 20:10:02 UTC
Your last alinea should have been in the original enhancement request.

Maybe it could be handy to create an ant-task that can export JARs (or
other files?) as artifacts to be included in other projects through
'Add Project'? It would be a generic solution to my particular 'problem'.
Comment 5 Jesse Glick 2004-12-15 20:26:23 UTC
The "artifact" isn't currently a disk format, it's information
provided directly from the subproject.
Comment 6 Jesse Glick 2004-12-15 20:39:01 UTC
*** Issue 50621 has been marked as a duplicate of this issue. ***