You typically should not pull in mvc beans as test cases do not run in a servlet container. If you really want to do this and you are using the newest version of Spring you can use the test-mvc package for that. There is more on that in the reference docs.
I am going to give explanation of above query as per my understanding.
Actually what I understand that, you are trying to inject a class in test class. Because both are handled by different container so your object will not be
wired automatically. you have below option's to test it.
And I am assuming that the classes you are trying to inject is POJO and application is pure java application not web application.
Below is step for java application not running through any server:
1. configure the POJO classes in context file . And load the context file through implementation classes like
ClasspathXmlApplicationContext Or FileSystemXmlApplicationContext etc.
then get the bean thriugh that and use.
2. If this is Web appplication then you have to build your test classes in support of test package.
Please UseCodeTags <- click when posting code snippets.
Yes. The SpringJUnit4ClassRunner class will take care of making the test case spring aware. The context configuration should be your spring config classes or xml files (depending if you are doing your configuration in xml or java), this part will take care of initializing your contexts for you. The class involved in your test case (typically this should be only 1 if you are writing good unit tests) may have autowired dependencies. In this case they must be defined in the xml or java config file you provide, so that it can be injected by Spring. Best practice says you create a smaller config file for that test case. This way you are not creating a bunch of beans for stuff that is not under test. You can also use a framework like Mockito to inject mocks rather than real objects. In this way you can prevent other classes from becoming involved in the code under test.
While you could could use component scan in your test config you can also just create the beans you need.
(this bean would be defined in the application-context.xml that is being fed to the @ContextConfiguration)