title: How to unit test a method called by constructor Spring Boot
body: <p>I would like to know how to unit test register() method in the below code</p>
  <pre><code>@Component
  @Slf4j
  public class Abc {
      private Xyz xyz;
  
      @Autowired
      public Abc(Xyz xyz) {
  
          this.xyz = xyz;
          try {
              register();
          } catch (Exception e) {
              log.warn(&quot;Unsupported&quot;);
          }
      }
  
      private void doSomething(String ts) {
         //do Something
      }
  
      private void register() {
          //register something
      }
  }
  </code></pre>
  <p>How can I unit test this method in a spring boot application. When I try some unit tests the constructor is called even before test method execution</p>