Specify jvm arguments in the testng template xml for eclipse testng plugin?

2,299 views
Skip to first unread message

Zhao Wang

unread,
Feb 7, 2014, 9:05:54 PM2/7/14
to testng...@googlegroups.com
We have some jvm arguments to specify when running the test. Is it possible to specify the jvm arguments in the testng template xml just for testng eclipse plugin?

I know I can put those arguments in the setting for testng eclipse plugin. Just want to put it in xml so I can share with the team and save some work.

I have tried to find instruction in the documents on the website, but didn't find anything about it. i didn't see any body ask that question either.

My Current template xml is like this

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >

<suite name="templateWithListener" verbose="1">
    <listeners>
      <listener class-name="org.mytest.testng.BasicExecutionListener"></listener>
      <listener class-name="org.mytest.testng.BasicTestListener"></listener>
  </listeners>
</suite>

Thanks. 

Krishnan Mahadevan

unread,
Feb 7, 2014, 11:45:52 PM2/7/14
to testng...@googlegroups.com
To the best of my knowledge you can't do this via the TestNG template xml file.

But you could try doing it via a BeanShell as a Method Interceptor.

To understand how to use beanshell in your TestNG suite xml file, refer to my blog post : http://rationaleemotions.wordpress.com/2013/08/21/beanshell-and-testng/

Within the beanshell tag, you could try using System.setProperty("myJVMArgName", "myJVMArgValue");

Here's how your complete suite file can look like :

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">

<suite name="Suite" parallel="false" verbose="2">

<test name="Test">

<method-selectors>

<method-selector>

<script language="beanshell"><![CDATA[ System.setProperty("username","TestNG");return true;]]>

</script>

</method-selector>

</method-selectors>

<classes>

<class name="organized.chaos.testng.FunnyTest" />

</classes>

</test> <!-- Test -->

</suite> <!-- Suite -->


And here's my test class

package organized.chaos.testng;


import org.testng.annotations.Test;


public class FunnyTest {

    @Test

    public void f1() {

        System.out.println("You passed " + System.getProperty("username") + " as the username");

    }

}


And here's the output:

...

... TestNG 6.8.6 by C?dric Beust (ced...@beust.com)

...


[TestNG] Running:

  /Users/krmahadevan/githome/PlayGround/testbed/src/test/resources/beanshell.xml


You passed TestNG as the username

PASSED: f1


===============================================

    Test

    Tests run: 1, Failures: 0, Skips: 0

===============================================



===============================================

Suite

Total tests run: 1, Failures: 0, Skips: 0

===============================================


[TestNG] Time taken by org.testng.reporters.EmailableReporter2@26f4a3a1: 8 ms

[TestNG] Time taken by org.testng.reporters.jq.Main@6deb59b1: 36 ms

[TestNG] Time taken by org.testng.reporters.XMLReporter@3d9061ec: 8 ms

[TestNG] Time taken by org.testng.reporters.JUnitReportReporter@5b013dc8: 3 ms

[TestNG] Time taken by [FailedReporter passed=0 failed=0 skipped=0]: 0 ms

[TestNG] Time taken by org.testng.reporters.SuiteHTMLReporter@27420a71: 11 ms


Would this work for you ?



Thanks and Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"


--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to testng-users...@googlegroups.com.
To post to this group, send email to testng...@googlegroups.com.
Visit this group at http://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/groups/opt_out.

Zhao Wang

unread,
Feb 9, 2014, 4:05:09 PM2/9/14
to testng...@googlegroups.com
I just tested with this solution, it does not work for my case. I think the reason is because we are relying on certain arguments to make a build before running the test. 

For this issue, I think I have to stay with specifying the jvm arguments in the testng plugin, which is good enough. 

The blog post is helpful to me. I could use the same solution there to solve another problem I may have in the future. 

Thanks for the help. Have a wonderful weekend. :)
Reply all
Reply to author
Forward
0 new messages