は私がする必要があります。テスト結果を待ち受けるTestWatcherオブジェクトを作成します。このTestWatcherは、テストを含む各JUnitクラスに含まれています。スイート全体が完了したときに聴くリスナーがいましたが、プログラムで追加する必要がありました。 TeamCityを使用してテストを実行し結果を生成しているので、私はその能力を失ったと考えています。 TeamCityの結果を含むPDFレポートを作成するように求められました。私が知る必要があることは、いつテストが終了したかで、いつレポートを作成するのかを知ることができます。 TestWatcherを使うだけでこれを達成することができますか?JUnitがTestWatcherを使うだけで終了する方法を教えてください。 <ul> <li></p>テストがチームシティー経由で開始されます</li> </ul> <p>テストからレポートを作成した情報を収集</li> <li>をテスト</li> <li>を見る:
以下は私のTestWatcherの外観です。 BaseTestResultは、テストの結果を含む単なるクラスであり、それらを簡単に印刷するために整理します。私はまた、セレンを使用していますし、ドライバ変数の型はwebdriverをである:
@Rule
public TestWatcher watchman = new TestWatcher() {
private BaseTestResult currentTest;
private long startTime;
private long endTime;
@Override
protected void starting(Description d) {
startTime = System.currentTimeMillis();
currentTest = new BaseTestResult(d);
currentTest.setBrowser(type);
if (d.getAnnotation(TestDescription.class) != null) {
currentTest.setDescription(d.getAnnotation(
TestDescription.class).description());
}
currentTest.setSuite(d.getTestClass().getName());
}
@Override
protected void succeeded(Description d) {
currentTest.setSucceeded(true);
}
@Override
protected void failed(Throwable e, Description d) {
currentTest.setThrowable(e);
}
@Override
protected void finished(Description d) {
endTime = System.currentTimeMillis();
currentTest.setRuntime(endTime - startTime);
String fileName = d.getMethodName() + type + ".png";
File srcFile = ((TakesScreenshot) driver)
.getScreenshotAs(OutputType.FILE);
String filePath = "./screens/" + fileName;
try {
FileUtils.copyFile(srcFile, new File(filePath));
currentTest.setScreenshotPath(filePath);
} catch (IOException e) {
log.severe(e.toString());
}
if (currentTest.getSucceeded()) {
BaseListener.getSuiteResult().addPassed(currentTest);
} else {
BaseListener.getSuiteResult().addFailed(currentTest);
}
// Quit, the web driver
if (driver != null) {
driver.quit();
}
}
};
はところで、私はちょうど私達の両方が古い方法「夜警」で指定された当社のテスト_Watcher_ :)答えを –
感謝を使用することを実現し、これは間違いのステップである私のために働きました正しい方向。複数のクラスがある場合はどうなりますか?私は複数のテストクラスを持つ予定であり、実行するすべてのテストクラスの結果からレポートを作成したいと考えています。 –
あなたのコメントに答えるために、分で答えを編集するつもりです。 –