-1

I have a constructor which initialises some external dependency. This constructor is called in the main function. How do I mock the calling of this constructor using JUnit4?

Progman
  • 16,827
  • 6
  • 33
  • 48

1 Answers1

1

You can:

  1. Using PowerMockito.
  2. Redesign your code to be testable to avoid creating new instances within the constructor. Read and try to use dependency injection instead (DI).

Highly recommend (2) because you should to avoid using PowerMockito. You will never need PowerMockito if you have a good design to have your code testable.