0

I want to make custom report using testng + reportNG(both installed)

I m writing java file to run selected classes, i m using testNG api, but can't figure out how to call its methods and make my own suite

I already have xml file that runs all eight java tests - suite_basic_links_working.xml I want to learn how to write java, not xml file to run same suite!

    public class Suite_runner_tets_links {
    TestNG suite_for_testing_links ;
    @Test
    public void main() {
      suite_for_testing_links.setDefaultSuiteName("NAIMI.KZ selenium + testng report ");
      List <> some_classes_to_run[] = new ArrayList();

      some_classes_to_run.add("C:\\Users\\www\\ERJAN_NAIMIKZ_ALL\\erjan_2_naimikz_test\\erjan\\testNG\\links_test\\Onas_url_click_test.java");
      some_classes_to_run.add("C:\\Users\\www\\ERJAN_NAIMIKZ_ALL\\erjan_2_naimikz_test\\erjan\\testNG\\links_test\\Podbo_specialista_url_click_test.java");

      suite_for_testing_links.setTestClasses(some_classes_to_run);
      suite_for_testing_links.run();
    /*  
      TestNG tng = new TestNG();
      List suites = Lists.newArrayList();
      suites.add("c:/tests/testng1.xml");
      suites.add("c:/tests/testng2.xml");
      tng.setTestSuites(suites);
      tng.run();*/

  }
  @BeforeSuite
  public void beforeSuite() {
      suite_for_testing_links = new TestNG();
      System.out.println("here!!! "+suite_for_testing_links.getOutputDirectory()) ;
      suite_for_testing_links.setOutputDirectory("C:\\Users\\www\\ERJAN_NAIMIKZ_ALL\\erjan_2_naimikz_test\\erjan_custom_testng_report");
  }

  @AfterSuite
  public void afterSuite() {

  }

this is my directory in eclipse, i want to run 2 tests - blog_url_click_test.java and logo_url_clik test.

k

ERJAN
  • 23,696
  • 23
  • 72
  • 146

1 Answers1

0

Look at TestNG project website. http://testng.org/doc/documentation-main.html You can easily find a @Factory example where you can put all of your test class into one method and then just run it.

public class WebTestFactory {

      @Factory
      public Object[] createInstances() {
       Object[] result = new Object[10]; 
       for (int i = 0; i < 10; i++) {
          result[i] = new WebTest(i * 10);
        }
        return result;
      }
    }

When you start this code you should notice that objects initializing is random. And if you want to make some hierarchy you will need to read for example this topic How to order TestNG Factory execution given a single method test and sortable test data?

Community
  • 1
  • 1