2012-07-16 203 views

回答

7

我想出了這一個。

您可以做的是在BlockJUnit4ClassRunner中覆蓋createTest(),並將super.createTest()的結果傳遞給您選擇的方法。例如:

public class CustomTestRunner extends AbstractTestRunner { 

    @Override 
    public abstract void prepareTest(final Object test) { 
    // have your way with the test object 
    } 
} 

public abstract class AbstractTestRunner extends BlockJUnit4ClassRunner { 

    @Override 
    public Object createTest() throws Exception { 
     Object test = super.createTest(); 
     prepareTest(test); 
     return test; 
    } 

    public abstract void prepareTest(final Object test); 
}