如何在Java中的不同类中实现函数(testNG)

时间:2013-12-25 09:32:57

标签: java testng

我有一个Java(testNG)程序,如下所示。现在函数列表不断增长,我想在一个单独的java类中实现每个/ setof函数。这样做的最佳方法是什么?

package myPackage;

import somepackages.*;

public class myClass {

  declare variable1;
  declare variable2;
  .
  .
  declare variableN;


  @BeforeTest(alwaysRun=true)
   public void beforeRun(){
   //do something
   }

  @Test
  public void test(){
    funtion1();
  }

  @AfterTest
  public void afterTest() {
   //do somthing
  }

  public void function1() {
  //calls function2, function3....
  }

  public void function2() {
  //do something
  }
  .
  .
  .
  .
  public void functionN() {
  //do something
  }


}

2 个答案:

答案 0 :(得分:0)

您可以将类从一个扩展到另一个并使用上一个创建的类的对象...

public class myClass {
//some methods
}
public class myClass1 extends myClass {
//some another methods
}
public class myClass2 extends myClass1 {
//some another methods
}

答案 1 :(得分:0)

Test1.java

public abstract class Test1 {
    public abstract void fun1();
    public abstract void fun2();
    public abstract void fun3();
    public abstract void fun4();
}

Test2.java

public abstract class Test2 extends Test1 {

    @Override
    public void fun1() {
      //fun1 defination
    }

    @Override
    public void fun2() {
      //fun2 defination
    }
}

Test3.java

public class Test3 extends Test2 {

    @Override
    public void fun3() {
      //fun3 defination
    }

    @Override
    public void fun4() {
      //fun4 defination
    }
}

Test.java

public class Test{
    public static void main(String args[]) {
        Test1 test = new Test3();
   }
}