title: Getting "Too few invocations" on unit test with spock
body: <p>For simplicity let's take a very simple class:</p>
  
  <pre class="lang-java prettyprint-override"><code>public class TestingClass {
  
      public void method1(){
          System.out.println("Running method 1");
          method2();
      }
  
      public void method2(){
          System.out.println("Running method 2");
      }
  }
  </code></pre>
  
  <p>Now I'm writing a simple test, which checking that when we invoke <code>method1()</code>, <code>method2()</code> is invoked:</p>
  
  <pre class="lang-java prettyprint-override"><code>class TestingClassSpec extends Specification {
      void "method2() is invoked by method1()"() {
          given:
          def tesingClass = new TestingClass()
  
          when:
          tesingClass.method1()
          then:
          1 * tesingClass.method2()
      }
  }
  </code></pre>
  
  <p>by executing this test, I'm getting the following error:</p>
  
  <blockquote>
    <p>Running method 1 Running method 2</p>
    
    <p>Too few invocations for:</p>
    
    <p>1 * tesingClass.method2()   (0 invocations)</p>
  </blockquote>
  
  <p>Why I'm getting this error? Printed log is show that <code>method2()</code> was invoked.</p>