在调用方法之前先调用方法

时间:2020-03-26 16:26:32

标签: java class methods annotations allure

我有以下Java代码,其中使用了“魅力注释”,问题在于,对于每种方法,我都必须复制该代码以显示当前的“步骤”,请参见下面的代码:

@Step("Step 1")
public void step1(){
Method method = new Object() {} .getClass().getEnclosingMethod();
System.out.println("Running step: " + method.getAnnotation(Step.class).value());
// ... more code here
}

@Step("Step 2")
public void step2(){
Method method = new Object() {} .getClass().getEnclosingMethod();
System.out.println("Running step: " + method.getAnnotation(Step.class).value());
// ... more code here
}

我在许多这样的类中都有这个,我想知道是否可以通过某种方式避免这种情况,例如:在调用这些方法调用之前,在设置方法以打印注释之前...

0 个答案:

没有答案
相关问题