Test Spring Bean with Junit and loading bean definition xml
While testing Spring beans we often need to load the spring bean configuration file and inject beans into Junit Test class. Below two annotations will come handy:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
The usage of the annotations are shown in below example:
/** *These two annotation will help you loan */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations={"/spring-config/beans.xml"}) public class ProcessTestHumanAndServiceTaskExample { private String filename = "D:/junoprojects/activiti_samples/activiti-sample/HumanAndServiceTaskExample.bpmn"; /** * Inject repository service */ @Resource private RepositoryService repositoryService; /** * Inject runtime service */ @Resource private RuntimeService runtimeService; /** * Inject task service */ @Resource private TaskService taskService; @Test public void startProcess() throws Exception { ........... ........... } } |
Leave a Reply