7

I'm using Netbeans with Maven and TestNG. When running tests with the maven surefire plugin, I can setup some configuration parameters, in particular the logging level used for my tests (trace):

-Dorg.slf4j.simpleLogger.defaultLogLevel=trace
-Dorg.slf4j.simpleLogger.logFile=System.out

However, when running a specific test file (CTRL + F6) or test method ("run focused test method"), Netbeans does not use surefire (which is good) and therefore ignores those parameters.

Is there a way to change the JVM parameters used by Netbeans when it runs tests that way?

This is somewhat similar to this other post but my question is specific to Netbeans.

Community
  • 1
  • 1
assylias
  • 321,522
  • 82
  • 660
  • 783
  • NetBeans IDE: Adding/Changing JVM command line args You can find all the instructions here: https://web.archive.org/web/20131217060421/https://blogs.oracle.com/charliebrown/entry/netbeans_ide_adding_changing_jvm – cristi Nov 16 '12 at 23:20
  • 1
    I think these are the settings for the JVM that runs IDE. The tests are run in a separate JVM AFAIK. – assylias Nov 17 '12 at 07:26

4 Answers4

6

From the documentation of Netbeans 7.2 (see Netbeans 7.2 changes, section Maven) :

... Now Test File always runs Maven by default, just like Test Project ...

What version of Netbeans are you using? Probably you should just upgrade to 7.2.

Zólyomi István
  • 2,401
  • 17
  • 28
  • If I create a new Test class and run `test file`, it runs with Maven. If I run it a second time, it runs with Ant... And `run focused test` seems to always run with ant. – assylias Nov 20 '12 at 06:47
  • It's probably a Netbeans bug then. You should report it if no such ticket exists already. – Zólyomi István Nov 20 '12 at 09:24
5

In the Project Properties, you can create profiles under Run. In theses profiles you can customize VM Options. You can add your parameters here, create a Test config and Run config.

Alexandre Lavoie
  • 8,711
  • 3
  • 31
  • 72
  • When using Maven, it seems that this option can't be changed (if I add VM Options, close the properties window, reopening it: the VM Options are blank again). – assylias Nov 13 '12 at 07:37
  • I think this is exactly what you are looking for : http://stackoverflow.com/questions/10851534/how-to-set-system-properties-using-netbeans-7-2-and-maven – Alexandre Lavoie Nov 13 '12 at 07:39
  • My problem is that when I run an individual test, Netbeans does not call Maven but runs the test directly (I suppose by calling an ant script in the background). So the Maven configuration is only used when testing the whole project. I have already configured Maven in the way described in your link. – assylias Nov 13 '12 at 07:47
  • Sorry, can't help much. I've never done Maven projects on NetBeans at the moment. – Alexandre Lavoie Nov 13 '12 at 07:55
  • Well, I have no access to Netbeans at the moment - but it seems that if using the run profiles as suggested is not working, then what you want seems not possible at all. I think it could be considered a bug (or at least an annoying shortcoming), given that it is a trivial thing to expect from the IDE. If you could not find an answer on the netbeans forums, I suggest you file a request in their JIRA. – javabeats Nov 13 '12 at 14:11
1

Set fork property in the surefire plugin configuration in Maven. This will start a new JVM. Now, the second part is how to read the JVM parameters that you want into the new JVM. Depending on what you want to do, you might need to be read them from the environment.

Akber Choudhry
  • 1,755
  • 16
  • 24
1

In my case i went to project/properties, then "Actions" category. There you'll find "Test file" and "Debug test" actions. Select them and place whatever properties you need in "Set properties" box.

Not sure if this is only applicable for Maven projects...

Jaime Casero
  • 371
  • 2
  • 6