「BeforeTest」は1回だけ印刷され、2回は印刷されません。私は間違って何をしていますか?
***申し訳ありません。私はあなたが@BeforeTestに書かれていることに気づいていませんが、あなたの例では、@BeforeTestは@BeforeClassとほぼ同じです。
@BeforeClassは」あなたのテスト方法は、ない異なった!
//Example
package test;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
public class Tests {
private String bClass;
private String bMethod1;
private String bMethod2;
@BeforeClass
public void beforeClass() {
bClass = "BeforeClass was executed once for this class";
}
@BeforeMethod
public void beforeMetodTest1() {
bMethod1 = "It's before method for test1";
}
@Test
public void test1() {
System.out.println(bClass);
System.out.println(bMethod1);
}
@BeforeMethod
public void beforeMethodTest2() {
bMethod2 = "It's before method for test2";
}
@Test
public void test2() {
System.out.println(bClass);
System.out.println(bMethod2);
}
}
@BeforeClassは、このクラスでは、あなたのすべてのテストメソッドの前に、一度だけ実行されます、同じクラスで宣言されなければならない。@BeforeMethodは、テストメソッドの前に実行されますそれ以前に書かれています。
@BeforeClassは、テストクラスで1つしか差がありません@BeforeMethod!(@BeforeClassの場合、それらは順番に実行されますが、テストの正しい構成ではありません)
P.S.私の英語には申し訳ありません。