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 46298 - Allow to specify JVM parameters for running JUnit tests
Summary: Allow to specify JVM parameters for running JUnit tests
Status: NEW
Alias: None
Product: java
Classification: Unclassified
Component: Project (show other bugs)
Version: 3.x
Hardware: All All
: P2 blocker with 6 votes (vote)
Assignee: Tomas Zezula
Keywords: UI
: 62337 122677 185747 (view as bug list)
Depends on:
Blocks: 152183 211055
  Show dependency tree
Reported: 2004-07-19 16:44 UTC by Birdy27
Modified: 2013-07-03 06:51 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 Birdy27 2004-07-19 16:44:18 UTC
I' useing the given-junit UI from Netbeans 3.6 to
create and run tests.
I noticed that while assert works in my program,
it does not work while testing (Strg+Alt+L).

I have JUnit Execution set to "External" and
external execution has asserts enabled (I also
enabled asserts whereever possible.)

I asked in and got
the reply to post it as a bug here.
Comment 1 Marian Petras 2004-07-19 16:50:47 UTC
The assert statements are ignored because the JVM running the tests
ignores the statements (which is the default behaviour). The problem
is that there is no way for a user how to enable interpreting of the
statements. Generally, there is no way how to pass a JVM parameter to
the JVM starting the tests.
Comment 2 Marian Petras 2004-11-30 16:04:33 UTC
Confirmed. It is possible to do it neither in NB 3.6 nor in NB 4.0.
Comment 3 Marian Petras 2004-12-07 10:49:09 UTC
The problem is that when a separate JVM is started (forked) for
running JUnit tests, no JVM parameters are specified for it and there
is no GUI for doing it.

Currently the only way (I know about) of how to specify JVM parameters
for JVM running JUnit tests is to override Ant target
"-init-macrodef-junit". To override the target, simply define it in
file build.xml in the project's root directory. Once it is defined
there, it will be used instead of the default definition specified in
file nbproject/build-impl.xml.

To define the target in build.xml, insert the following lines just
below tag <import file="nbproject/build-impl.xml"/>:

    <target name="-init-macrodef-junit">
        <macrodef name="junit"
            <attribute name="includes" default="**/*"/>
                <junit showoutput="true"
                    <jvmarg value="-ea"/>
                    <batchtest todir="${build.test.results.dir}">
                        <fileset includes="@{includes}"
                        <path path="${run.test.classpath}"/>
                        <propertyref prefix="test-sys-prop."/>
                        <mapper to="*"
                    <formatter usefile="false" type="brief"/>

The only difference (except formatting) between the original
definition and the new one is that the new definition contains element
<jvmarg value="-ea"/>. One may customize JVM parameters by replacing
"-ea" with any legal JVM parameters.
Comment 4 Marian Petras 2005-10-19 16:25:51 UTC
*** Issue 62337 has been marked as a duplicate of this issue. ***
Comment 5 Jiri Vagner 2007-03-22 10:15:45 UTC
What about setting value of "jvmarg" attrib for forked JVM in ...

1. Tools-> Options ->jUnit (global settings for all projects) ?
2. Actual Project -> Properties -> new "Test" card with jUnit settings?

Would it be possible?
Comment 6 Marian Petras 2008-11-25 19:52:43 UTC
Reassigned to "java/j2seproject".

Issue #122677 ("Add run.test.jvmargs to") is related.
Comment 7 ulfzibis 2009-07-15 08:42:42 UTC
See also Issue 152183, maybe related.
Comment 8 Jesse Glick 2010-05-10 19:48:51 UTC
*** Bug 122677 has been marked as a duplicate of this bug. ***
Comment 9 Jesse Glick 2010-05-10 19:49:17 UTC
*** Bug 185747 has been marked as a duplicate of this bug. ***
Comment 10 beginner_ 2013-07-03 06:51:58 UTC
I needed to try a JVM option for a unit test to and found this post on SO:

So you can set environment variable JAVA_TOOL_OPTIONS to the required JVM options and they will be picked up by any newly starting JVM.

Also see:

In my case I set it to -Dfile.encoding=UTF8

and that was picked up correctly after restarting netbeans 7.2.1 on Windows 7.