title: How to test class with @Autowired using Spock
body: <p>I have a class in <code>src/groovy</code> like this</p>
  
  <pre><code>public class MyClass {
  
  @AutoWired
  SomeOtherClass someOtherClass
  
  String test() {
      return someOtherClass.testMethod()
  }
  }
  </code></pre>
  
  <p>When I write a test for this method I am getting an error: <code>Cannot invoke method testMethod() on null object</code>.</p>
  
  <p>This is my test :- </p>
  
  <pre><code>def "test test" () {
      expect:
          myClass.test() == "somevalue"
  }
  </code></pre>
  
  <p>What am I doing wrong? Is there a way to mock the <code>@Autowired</code> class?</p>