This week's book giveaway is in the JavaFX forum.
We're giving away four copies of Introducing JavaFX 8 Programming and have Herbert Schildt on-line!
See this thread for details.
The moose likes Testing and the fly likes Runnig junit in App server Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Introducing JavaFX 8 Programming this week in the JavaFX forum!
JavaRanch » Java Forums » Engineering » Testing
Bookmark "Runnig junit in App server" Watch "Runnig junit in App server" New topic

Runnig junit in App server

junit ant

Joined: Dec 01, 2005
Posts: 2
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.


- 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" >
<fileset dir="${tomcat.webapps}" includes="**/*.*"/>
<fileset dir="${tomcat.shared}" includes="**/*.*"/>
<pathelement location="${cvs.dir}/config/hibernate.cfg.xml"/>

<batchtest fork="yes" todir="${results.dir}/raw/">
<formatter type="xml"/>
<fileset dir="${test.dir}">
<include name="**/*Test*.java"/>
junit ant

Joined: Dec 01, 2005
Posts: 2
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(
Lasse Koskela

Joined: Jan 23, 2002
Posts: 11962
Instead of


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 32609

"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.


[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
I agree. Here's the link:
subject: Runnig junit in App server
jQuery in Action, 3rd edition