cancel
Showing results for 
Search instead for 
Did you mean: 

How to write junit test with existing spring configuration

yongqiang
Champ in-the-making
Champ in-the-making
Greeting Everyone,

I get a project which use activiti for years. There are a lot beans defined in spring xml files need to be loaded for process flow. Now, I like to build junit test for some process flows.

From what I understand, ActivitiRule will only look up activiti.cfg.xml by default. It will not load bean from spring xml files.

Are there any configuration I can let ActivitRule to understand definition from Spring XML?

Further, I tried approach like below

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:spring/applicationContext*.xml")

It does help to load bean but I counter issue such as "Caused by: org.h2.jdbc.JdbcSQLException: Table "ACT_HI_PROCINST" already exists; SQL statement:"

I did some research, people say we can clean h2 db before test. But question is, how?

Any advice, please.


Regards,
Yong
1 REPLY 1

jbarrez
Star Contributor
Star Contributor
No, the ActivitiRule does not support that.

But if it's a spring project, it's probably a better idea to run it with a Spring unit test runner, and inject the processEngine bean in the test.