Using -methods param programatically

16 views
Skip to first unread message

Aaron

unread,
Feb 5, 2012, 9:50:18 PM2/5/12
to testng-users
Hi. I am running testng programatically from Java code. How do I pass
the -methods parameter to run specific tests?

I was sort of able to get it calling:
TestNG.main()

and passing in the parameters I wanted to set, but then I am confused
about what tng.run() does. Does run() just call the main method?

Calling the main() method also seems to make my listener execute twice
per test.

What is the best way to programatically run testng with the -methods
parameter?

Cédric Beust ♔

unread,
Feb 6, 2012, 1:34:37 PM2/6/12
to testng...@googlegroups.com
You should probably not mix the approaches: either you call main with command line parameters or you use the API.

Since you're already using the API, you can specify which methods to run by creating a corresponding XML entry. Take a look at TestNG#createCommandLineSuitesForMethods, which does exactly that (translate -methods into the API).

-- 
Cédric





--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to testng...@googlegroups.com.
To unsubscribe from this group, send email to testng-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.


Aaron

unread,
Feb 11, 2012, 9:33:12 PM2/11/12
to testng-users
Thanks Cedric. I see the code now, though it requires me to basically
copy and paste your methods into my code. Why not have some kind of
public method that allows users to programatically add tests.
Something like:
tng.addTests()

or something of the like. Is there a feature request queue for TestNG?
I would love that feature so I don't have to go through your code and
look at various private methods to figure out how to do this.

Thanks -Aaron

Aaron

unread,
Feb 11, 2012, 10:57:00 PM2/11/12
to testng-users
Ah, I see. You construct the suite programatically to re-create the
testng.xml, kind of like creating a DOM.

I got it working now.

Cedric, I think this could be clearer in the docs. Would you like me
to edit the documentation page, specifically the running testng
programatically section to help make this clearer to others who might
have similar questions?

Cédric Beust ♔

unread,
Feb 12, 2012, 3:16:20 AM2/12/12
to testng...@googlegroups.com
Hi Aaron,

Sure. If you could send your edits as a pull request, that would be even better.

Thanks!

-- 
Cédric




Aaron

unread,
Feb 13, 2012, 10:37:27 AM2/13/12
to testng-users
Hi Cedric:
> If you could send your edits as a pull request, that would be even
better.

Not sure what you mean. Do I check the docs out of svn or something?

Cédric Beust ♔

unread,
Feb 13, 2012, 1:33:16 PM2/13/12
to testng...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages