微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

JUnit 在访问服务类 stepexecution 时给出 NullPointerException

如何解决JUnit 在访问服务类 stepexecution 时给出 NullPointerException

我有一个要测试的服务类。

public class MyService{
  private final MyConfig myconfig;
  private final WebClient webClient;
  private String result;
  private StepExecution stepExecution;

  @BeforeStep
  public void saveStepExecution(){
    this.stepExecution = stepExecution);
  }

  @AutoWired
  MyService(
    MyConfig myconfig,WebClient webClient) {
    this.myconfig = myconfig;
    this.webClient = webClient;
  }

  public void someMethod(){
    // does some stuff with stepexecution
  }
}

我的 Junit 测试用例是:

@Test
public void sometest(){
  MyService myservice = new MyService();
  myservice.someMethod();
}

但是它在 stepExecution 给出了 Null 指针,这是显而易见的。那么,我该如何通过 JUnit 测试方法的 stepexecution 呢?

解决方法

这可能不是您要找的答案。我没有足够的声誉来发表评论或改进您的问题,但是,我觉得您的问题与此类似。

@BeforeStep method is not called during unit test execution

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。