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.

2

4 Answers 4

6
+100

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.

2
  • 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, 2012 at 6:47
  • It's probably a Netbeans bug then. You should report it if no such ticket exists already. Nov 20, 2012 at 9: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.

5
  • 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, 2012 at 7:37
  • I think this is exactly what you are looking for : stackoverflow.com/questions/10851534/… Nov 13, 2012 at 7: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, 2012 at 7:47
  • Sorry, can't help much. I've never done Maven projects on NetBeans at the moment. Nov 13, 2012 at 7: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, 2012 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.

1
  • I don't think it has to do with the forkMode. The tests I mention are running with ant.
    – assylias
    Nov 20, 2012 at 6:48
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...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.