For simplicity, we take a very simple class:
public class TestingClass { public void method1(){ System.out.println("Running method 1"); method2(); } public void method2(){ System.out.println("Running method 2"); } }
Now I am writing a simple test that checks that when method1 () is called, method2 () is called:
class TestingClassSpec extends Specification { void "method2() is invoked by method1()"() { given: def tesingClass = new TestingClass() when: tesingClass.method1() then: 1 * tesingClass.method2() } }
by running this test, I get the following error:
Execution Method 1 Execution Method 2
Too few calls to:
1 * tesingClass.method2 () (0 invocations)
Why am I getting this error? The print journal shows that method2 () was called.
source share