Java Mailing List Archive

http://www.ant-tasks.com/

Home » Ant Users List »

Ant Junit ignore annotation @ContextConfiguration

叶伟平

2011-12-20


Author LoginPost Reply
Hi, everyone!
I have a project which is builded on struts2.2.1, Hibernate3.6.3 and
Spring3.0.5, and I'm running unit tests with Ant. I wrote three
classes:

1. TestLoginAction (unit test class)
public class TestLoginAction extends BaseActionTransactionalTest { ... }

2. BaseActionTransactionalTest (common configuration)
@ContextConfiguration(
 locations = {
   "classpath:applicationContext-dao.xml",
   "classpath:test-applicationContext-resources.xml",
   "classpath:applicationContext-service.xml",
   "classpath:applicationContext-struts.xml"
 }
)
public abstract class BaseActionTransactionalTest extends
   StrutsSpringTransactionalTests { ... }

3. StrutsSpringTransactionalTests(transaction control)
@RunWith(SpringJUnit4ClassRunner.class)
@TestExecutionListeners({ TransactionalTestExecutionListener.class,
   DependencyInjectionTestExecutionListener.class,
   DirtiesContextTestExecutionListener.class })
@Transactional
public abstract class StrutsSpringTransactionalTests extends
   StrutsSpringTestCase implements ApplicationContextAware { ... }

It works fine with Eclipse, but when I run TestLoginAction in
Ant-Junit, it fails. The spring configure
files(applicationContext-dao.xml ...) are not loaded. It seem that the
"@(protected):

     <target name="test" depends="compile.test">
   <mkdir dir="${report.dir}" />
   <property name="tests" value="Test*" />
   <junit printsummary="yes" haltonerror="yes" haltonfailure="yes">
     <formatter type="plain" usefile="false" />
     <formatter type="xml" />
     <batchtest todir="${report.dir}">
       <fileset dir="${src.test.dir}">
         <include name="**/${tests}.java" />
       </fileset>
     </batchtest>
     <classpath refid="lib.test.classpath" />
     <classpath location="${build.home.classes}"/>
   </junit>
 </target>

 <target name="testrunner" depends="compile.test">
   <java classname="org.junit.runner.JUnitCore" >
     <classpath refid="lib.test.classpath" ></classpath>
     <classpath location="${build.home.classes}"/>
     <arg value="me.yibo.web.action.TestLoginAction"/>
   </java>
 </target>

if I run target “testrunner”, it works fine.

Best Regard!

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@(protected)
For additional commands, e-mail: user-help@(protected)

©2008 ant-tasks.com - Jax Systems, LLC, U.S.A.