TestNG Groupの例
【本シリーズの他のチュートリアルは続々と翻訳中で、分類:TestNGをクリックして表示します.】
【翻訳byは月QQ 605283073のようなのに】
原文住所:http://websystique.com/java/testing/testng-groups-example/
上一篇:TestNG Annotations例
ここではTestNGグループテストにおける
@BeforeGroups, @AfterGroups
@BeforeGroup注記付きメソッドは、このグループ内の任意のテストメソッドが実行される前に1回実行されます.
これと同様に@AfterGroups注記付きのメソッドは、このグループ内の任意のテストメソッドが実行された後に実行されます.
mvn clean test
あるいは最初の文章で述べた
TestNG eclipseプラグインこのテストを実行します.
@BeforeGroupは、このグループ内の任意のテストメソッドが実行される前に呼び出されます.
Group拡張:
mavenベースのプロジェクトを実用的に使用する場合はpomを構成できます.xmlのmaven-surefire-plugin
右ボタン
testng.xml file->
RunAs->TestNG Suite
]
ご覧のように
ui関連の試験方法と対応するbeforeGroup/afterGroupは実行されなかった.
【翻訳byは月QQ 605283073のようなのに】
原文住所:http://websystique.com/java/testing/testng-groups-example/
上一篇:TestNG Annotations例
ここではTestNGグループテストにおける
@BeforeGroups
,@AfterGroups 。
について説明するTestNG 。
。
, 。
--------------------------------------
@BeforeGroups, @AfterGroups
@BeforeGroup注記付きメソッドは、このグループ内の任意のテストメソッドが実行される前に1回実行されます.
これと同様に@AfterGroups注記付きのメソッドは、このグループ内の任意のテストメソッドが実行された後に実行されます.
package com.websystique.testng;
import org.testng.annotations.AfterGroups;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test;
public class TestNGGroupExample {
@BeforeGroups("security")
public void setUpSecurity() {
System.out.println("setUpSecurity()");
}
@AfterGroups("security")
public void tearDownSecurity() {
System.out.println("tearDownSecurity()
");
}
@BeforeGroups("database")
public void setUpDatabase() {
System.out.println("setUpDatabase()");
}
@AfterGroups("database")
public void tearDownDatabase() {
System.out.println("tearDownDatabase()
");
}
@BeforeGroups(value="ui")
public void setUpUI() {
System.out.println("setUpUI()");
}
@AfterGroups(value="ui")
public void tearDownUI() {
System.out.println("tearDownUI()
");
}
@Test(groups= "database")
public void testInsert(){
System.out.println("testInsert()");
}
@Test(groups= "database")
public void testUpdate(){
System.out.println("testUpdate()");
}
@Test(groups= "database")
public void testDelete(){
System.out.println("testDelete()");
}
@Test(groups= "security")
public void accessHomePage() {
System.out.println("accessHomePage()");
}
@Test(groups= "security")
public void accessAdminPage() {
System.out.println("accessAdminPage()");
}
@Test(groups= "ui")
public void openConfirmationDialog() {
System.out.println("openConfirmationDialog()");
}
@Test(groups= "ui")
public void openFileDialog() {
System.out.println("openFileDialog()");
}
}
mvn clean test
あるいは最初の文章で述べた
TestNG eclipseプラグインこのテストを実行します.
setUpSecurity()
accessAdminPage()
accessHomePage()
tearDownSecurity()
setUpUI()
openConfirmationDialog()
openFileDialog()
tearDownUI()
setUpDatabase()
testDelete()
testInsert()
testUpdate()
tearDownDatabase()
PASSED: accessAdminPage
PASSED: accessHomePage
PASSED: openConfirmationDialog
PASSED: openFileDialog
PASSED: testDelete
PASSED: testInsert
PASSED: testUpdate
===============================================
Default test
Tests run: 7, Failures: 0, Skips: 0
===============================================
===============================================
Default suite
Total tests run: 7, Failures: 0, Skips: 0
===============================================
@BeforeGroupは、このグループ内の任意のテストメソッドが実行される前に呼び出されます.
@AfterGroups 。
Group拡張:
, ui 。
testNG configuration xml ui 。
src/test/resources testng.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="tests">
<test name="backend">
<groups>
<run>
<exclude name="ui" />
</run>
</groups>
<classes>
<class name="com.websystique.testng.TestNGGroupExample" />
</classes>
</test>
</suite>
mavenベースのプロジェクトを実用的に使用する場合はpomを構成できます.xmlのmaven-surefire-plugin
pomx.ml :
ersion>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
</project>
右ボタン
testng.xml file->
RunAs->TestNG Suite
]
setUpSecurity()
accessAdminPage()
accessHomePage()
tearDownSecurity()
setUpDatabase()
testDelete()
testInsert()
testUpdate()
tearDownDatabase()
===============================================
tests
Total tests run: 5, Failures: 0, Skips: 0
===============================================
ご覧のように
ui関連の試験方法と対応するbeforeGroup/afterGroupは実行されなかった.