Kalpana V
Kalpana V

Reputation: 31

Method for adding testCases

I am running TestCases programatically like,

    TestListenerAdapter tla = new TestListenerAdapter();
    TestNG testng=new TestNG();
    testng.setTestClasses(new Class[] { UserGroupTest.class }); 
    testng.addListener(tla);
    testng.run();

I have kept 8 test cases inside UserGroupTest.class

Is it possible to add testcase by testCase instead of adding whole class file?? Because I want to run testcases under condition basis. How to do tat?

Upvotes: 0

Views: 136

Answers (1)

Cedric Beust
Cedric Beust

Reputation: 15608

If you only want to run certain methods from these classes, you have a few options:

  • Put these methods in a group and call testng.setGroups(..).
  • Create a testng.xml (in-memory is probably the easiest since you are using the API) that will mimic the following XML:

    <classes>
      <class name="test.methods.SampleMethod1">
        <methods>
          <include name="shouldRun1" />
          <include name="shouldRun2" />
    

Upvotes: 1

Related Questions