I have a TestRunner class that starts my TestNG like this:

TestRunConfigs configs = TestRunConfigs.parseCommandLine(args);

TestNG testRunner=new TestNG();

I need to provide some values to all tests in all my suites. I think ITestContext is the right way to do that. I just don't know where to do that. Any directions ?


TestContext is being initialized automatically by TestNg. You can access it from your test methods which are listed below (for doing that you need to specify the method parameter in its signature):

enter image description here

For some details you can refer to this post.

And here is my example of using TestConext with running tests programmatically:

public class Main {
    public static void main(String[] args) {
        TestListenerAdapter tla = new TestListenerAdapter();
        TestNG testng = new TestNG();
        testng.setTestClasses(new Class[] { Main.class });

    public void setUp(ITestContext cntx){
        cntx.setAttribute("option1", new String("My Option 1"));
        cntx.setAttribute("option2", new String("My Option 2"));

    public void testTest(ITestContext cntx){

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.