0

I am new to Spring and Junit testing. I am trying to understand use of @RunWith(SpringJUnit4ClassRunner.class) and @ContextConfiguration(locations= {/dao-context.xml}) on line 1 and line 2nd below in my test. dao-context has datasource , entityManagerFactory and TranasctionManager beans defined.

@RunWith(SpringJUnit4ClassRunner.class) //Line 1
@ContextConfiguration(locations= {/dao-context.xml}) //Line2
Public class ProductServiceTest{

@Autowired
private void ProductDao productDao

......
.......
}
Neha
  • 745
  • 4
  • 10
  • 18

1 Answers1

1

In order for the unit test to run a batch job, the framework must load the job's ApplicationContext. Two annotations are used to trigger this:

@RunWith(SpringJUnit4ClassRunner.class): Indicates that the class should use Spring's JUnit facilities

@ContextConfiguration(locations = {...}): Indicates which XML files contain the ApplicationContext.

See more at this official documentation.

Shanu Gupta
  • 3,699
  • 2
  • 19
  • 29