1

テストについて質問があります。

私は次のようなものを持っています:

@Test
public initializeMethod() {
//here I do something that is needed before my real test method
}

@Test (depends on initializeMethod) 
public myRealTest1{
//my test 1
}

@Test (depends on myRealTest1) 
public myRealTest2{
//my test 2
}

testng レポートで initializeMethod をスキップすることは可能ですか (つまり、レポートで実際のテスト数 (3 ではなく 2) を確認したいということです)?

4

2 に答える 2

1

実際の各テストメソッドの前にinitializeMethod()を実行する場合は、@BeforeMethodアノテーションを使用できます。@BeforeMethod:注釈付きメソッドは、各テストメソッドの前に実行されます。したがって、メソッドを次のように宣言する必要があります。

@BeforeMethod
public initializeMethod() {
//here I do something that is needed before my real test method
}

initializeMethod()を1回だけ実行する場合は、@BeforeClassアノテーションを使用できます。@BeforeClass:注釈付きメソッドは、現在のクラスの最初のテストメソッドが呼び出される前に実行されます。したがって、メソッドを次のように宣言する必要があります。

@BeforeClass
public initializeMethod() {
//here I do something that is needed before my real test method
}
于 2012-08-13T11:44:22.573 に答える
1

@Test注釈は、特にテストに使用されます。initializeMethod()非テストアノテーションを使用して、メソッドに適切にアノテーションを付ける必要があります。いくつかのオプションは次のとおりです。

@BeforeTest
@BeforeClass

その他の可能な注釈:

@BeforeSuite
@BeforeGroups
@BeforeMethod // if you want `initializeMethod()` run before every test.
于 2012-08-02T17:32:06.047 に答える