aspose file tools*
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
JavaRanch » Java Forums » Engineering » Testing
Bookmark "Runnig junit in App server" Watch "Runnig junit in App server" New topic
Author

Runnig junit in App server

junit ant
Greenhorn

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.

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

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(HibernateSessionFactory.java:58)
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Instead of

try


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

Joined: May 26, 2003
Posts: 31079
    
163

"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


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Runnig junit in App server