0

I have a service class to be tested.

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
  }
}

My Junit test case is:

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

But it gives Null pointer at stepExecution which is obvious. So, how shall I pass stepexecution from JUnit Test method?

usr_11
  • 548
  • 10
  • 31
  • Your code as shown contains several error (e.g. a `)` in `saveStepExecution` and calling a no-arg constructor `MyService()` while no such constructor is defined). Please post a [mre]. – Mark Rotteveel Mar 25 '21 at 11:14

1 Answers1

2

This might not be the answer you are looking for. I don't have enough reputation to leave a comment or improve your question but, I fell like your question is similar to this.

@BeforeStep method is not called during unit test execution

Raj Thugu
  • 37
  • 6