2

I'm wondering how I can write a program to run TestNG tests, still using the testng.xml file. For example, how do I make a class that can do this:

TestNG ng = new TestNG();
//ng.setTests("testng.xml") or something similar
ng.run();

I've looked at the documentation, but it's not very detailed, so I'm not sure if this is possible. Obviously, the comment should be replaced with the actual code to use the testng.xml file.

Do I need to use the TestNG configure method? Or does TestNG already have a method that does this that I missed?

1
  • Can you be more specific in your question as to why you would want to do this without actually using the TestNG runner? Commented Jul 5, 2014 at 16:59

1 Answer 1

1

I'm sure there are other options out there, but you could use:

TestNG ng = new TestNG(); 
String[] arg = {"testng.xml"};
ng.main(arg);

and that should work fine. It's the same as running TestNG from the command line with the xml file as the argument.

Sign up to request clarification or add additional context in comments.

1 Comment

I've used this as a solution to a similar problem I'm having, however it cannot find my test classes when executed? even though if I execute it manually it works perfect, but when being executed this way it cannot find my test classes

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.