Monday, 1 July 2013

Setup and Trigger test automation using testng through code

This post shows how we could use testng class,generating html report ,setting test classes through the code.

Please download following jars :
1. http://reportng.uncommons.org/ 
2. http://testng.org/doc/download.html

Following is the Java Code:

 public static void main()
{
    Testng tng=new TestNg();
    LinkedList<Class> ll=new LinkedList<Class>();
    ll.add(HTMLReporter.class);

   tng.setTestListenerClasses(ll);
   tng.setOutputDirectory("d:\\test");
   tng.setTestClasses(new Class[]{Test.class});
   tng.run();
}

Following is the sample test class :

class Test
{
 
  @Test
   public void fun() // this methods will pass
  {
    System.out.println("fun");
    Reporter.log("This is passed");  
  }

  @Test
   public void fun2() //this method will fail.
  {
    System.out.println("fun2");
    Reporter.log("This is failed");  
    throw new Error();

  }


  
}



No comments:

Post a Comment