我在项目中有以下代码:
public class KarateHook implements RuntimeHook
{
private Set<String> scenarios = ConcurrentHashMap.newKeySet();
private static final Logger logger = LoggerFactory.getLogger(KarateHook.class);
public KarateHook()
{
}
@Override
public void afterScenario(ScenarioRuntime sr)
{
//Adding all scenario names in my set
scenarios.add(sr.scenario.name)
}
@Override
public void afterSuite(Suite suite)
{
if(!scenarios.isEmpty()){
System.out.println("I will apply my logic....to process the scenarios");
}else{
System.out.println("No scenarios found");
}
}
}
一切正常,但是当我尝试使用 power mockito 为上述类运行 junit 时,我不知道如何从我的 Junit 初始化全局变量(Set scenario=new HashSet<>)并在我的真实类中使用它. 当我尝试在 Suite 方法之后运行测试用例时,它总是转到我的其他块。