title: Spring JUnit test autowired variable in tested class
body: <p>I'd like to test a class which has a resource injected via @Autowired annotation. </p>
  
  <pre><code>class TestedClass{
    @Autowired
    private MyResource resource
    ...
  }
  </code></pre>
  
  <p>How can I make this injection to work without modifying the tested class? The injection works fine in the test class, but not in the tested class:</p>
  
  <pre><code>@RunWith(SpringJUnit4ClassRunner.class)
  @ContextConfiguration(locations= "classpath*:/bean-definition.xml")
    public class TestedClassTest {
    TestedClass instance;
  
    //This works
    @Autowired
    private MyResource resource
  
    @Before
    public void setUp() throws Exception {
      instance = new TestedClass();
    }
  ...
  }
  </code></pre>
  
  <p>So the problem is probably how to pass the context to the tested class?</p>