Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Runnig junit in App server

 
junit ant
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Gurus,

I have a small requirement here. The application I need to test has been developed using the hibernate, struts framework. I need to write few unit test scripts for them. The application has Data Access Objects.

I started writing the unit-tests from the DAO. I could successfully build the war file using the build.xml for the application. The war file gets generated successfully. Now to deploy it in the tomcat server, what i am doing is running a small script that stops the tomcat server , copies the war file to webapps and then starts the server.

After this is over. I am trying to run the junit targets for testing the DAO. But i am not able to get the ant script read the hibernate.cfg.xml file. As a result my tests are not able to get the database connection.

Question...

- whether above architecture is correct ? Or is there ant other simple and easy step to get it done ?

- Is there a way to over come this error ?


-------below is the snipped of the code----------------------

<target name="tests" depends="prepare" description="run your test suite" >

<junit printsummary="yes" haltonfailure="no" showoutput="yes" >
<classpath>
<fileset dir="${tomcat.webapps}" includes="**/*.*"/>
<fileset dir="${tomcat.shared}" includes="**/*.*"/>
<pathelement location="${cvs.dir}/config/hibernate.cfg.xml"/>
</classpath>

<batchtest fork="yes" todir="${results.dir}/raw/">
<formatter type="xml"/>
<fileset dir="${test.dir}">
<include name="**/*Test*.java"/>
</fileset>
</batchtest>
</junit>
</target>
 
junit ant
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
forgot to paste the error trace...


[junit] net.sf.hibernate.HibernateException: net.sf.hibernate.HibernateException: /hibernate.cfg.xml not found
[junit] at com.x1.x2.common.util.HibernateSessionFactory.currentSession(HibernateSessionFactory.java:58)
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Instead of

try
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34179
340
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"junit ant",
Welcome to JavaRanch!

We're pleased to have you here with us in the Testing forum, but there are a few rules that need to be followed, and one is that proper names are required. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Thanks,
Jeanne
Bartender
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic