0
我有兩個類用於測試迴歸測試。在某些情況下,我們在類和我們通常使用斷言的方法中有多個測試方法。我想知道是否有任何方法可用,只能使用@Rule
測試方法才能使用該類中的最後一個方法。這裏是我的代碼:如何僅定義最後的測試方法斷言將涉及
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class JustOneClass extends ParentClass {
@Rule
public class GeneralRule articleHotspotRule = new class GeneralRule (this);
@Test
aMethod(){
Assert.assertTrue()
}
@Test
bMethod(){
Assert.assertTrue()
}
@Test
cMethod(){
Assert.assertTrue()
}
@Test
dMethod(){
if this assert is failed Assert.assertTrue()
}
}
我們有一個在這種情況下,我想這baseTest.after()
只會如果dMedthod
斷言失敗使用擴展TestWatcher
public class GeneralRule extends TestWatcher {
private ParentClass baseTest;
public GeneralRule (final GeneralRule generalRule) {
this.baseTest = generalRule;
}
@Override
protected void failed(final Throwable e, final Description description) {
baseTest.after();
}
}
另一個類。
你想創建一個規則,只有當TestClass的最後一個測試方法失敗時才執行TestClass的方法嗎?是嗎? – acdcjunior
它可能有助於解釋你正在嘗試解決的問題,而這看起來很奇怪 – tddmonkey
我只想在一個條件下執行一個方法base.after(),即如果assert方法失敗(標記爲up在de dMethod())中。 – user3360123