jakarta-cactus-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Pseudo Nym" <pseudonymor...@gmail.com>
Subject Are cactus tests running on the server?
Date Wed, 18 Oct 2006 15:27:31 GMT
I've been attempting, without any luck, to get server-side JUnit tests
to test my code in-container using the new, annotation-style JUnit 4
tests. I'm using the Ant 1.7 beta to deploy my code and run my tests,
as this version has JUnit 4 functionality built in. I attempted to use
both JUnitEE and Cactus to run my tests.

I was successfully able to get JUnitEE to run JUnit 3.8 style tests,
but the various permutations of configurations I tried using JUnit 4
failed to work. I tried with and without the JUnit4TestAdapter in a
suite() method. I was getting different errors depending on the setup
I was using; however, none of them worked.

My attempts to get cactus working seemed to meet with more success,
and the tests do run. However, I am skeptical as to whether my setup
is actually running the tests from the sever, and not on the local
box. The reason I say that is that when I forgot to package some jars
that were necessary to the build, the ant tests still ran and passed.
However, when I used the cactus servlet to run the tests manually,
they would fail.

Here's the relevant section of my ant script for my cactus tests.
Note, it's pretty messy at the moment, as the goal was more to get
things working than to have a clean final script.

	<!-- Create the war file -->
	<target name="cactus-war" depends="init" description="Generate the
runtime war">
		<property name="temp.war.file" location="${war.file}.tmp" />

		<delete dir="${dist.dir}" failonerror="false" />
		<mkdir dir="${dist.dir}" />

		<!-- todo: build actual war for actual app; then have cactified copy -->
		<war destfile="${temp.war.file}" webxml="web.xml" basedir="${dist.dir}">
		</war>
		<cactifywar srcfile="${temp.war.file}"
				destfile="${war.file}">
			<lib file="${test.jar.file}" />
			<lib file="${serverapp.jar.file}" />
			<lib dir="lib"/>
			<lib dir="${serverapp.lib.dir}" />
		</cactifywar>
		<delete file="${temp.war.file}" />
	</target>

 <target name="run-test" depends="init, cactus-war, deploy-war,
run-cactus-test" description="Run the tests on the defined containers"
/>

	<target name="run-cactus-test"
	    description="Run the tests on the defined containers">

		<!-- Run the tests -->
		<cactus warfile="${war.file}" fork="yes" failureproperty="tests.failed">
			<classpath>
				<path refid="cactus.classpath"/>
				<path refid="serverapp.classpath"/>
			</classpath>
			<containerset timeout="10000">
				<generic startuptarget="" shutdowntarget="" server="${test.server}" />
			</containerset>
			<formatter type="brief" usefile="false"/>
			<formatter type="xml"/>
			<batchtest todir="${test.log.dir}">
				<fileset dir="${serverapp.test.dir}">
					<!-- todo: do integration tests instead, once this is working -->
					<include name="**/*Test.java"/>
					<exclude name="**/*IntegrationTestSuite*.java"/>
					<exclude name="**/*IntegrationTest*.java"/>
				</fileset>
			</batchtest>
		</cactus>
		<fail if="tests.failed">Cactus JUnit test failures</fail>
	</target>

	<target name="deploy-war" depends="cactus-war" description="make and
deploy war">
		<echo level="info">Beginning (re)deployment of servlet at
${webserver.tests.url}</echo>
		<property name="servlet.deploy.maxwait" value="30000" />

		<delete file="${autodeploy.dir}/${war.file.name}" failonerror="false" />
		<echo level="info">Waiting for servlet to be undeployed...</echo>
		<waitfor maxwait="${servlet.deploy.maxwait}"
timeoutproperty="servlet.deploy.error">
			<not>
				<http url="${webserver.tests.url}" />
			</not>
		</waitfor>

		<fail if="servlet.deploy.error">Unable to undeploy previous servlet</fail>

		<copy file="${war.file}" todir="${autodeploy.dir}" overwrite="true" />

		<echo level="info">Waiting for servlet to be deployed...</echo>
		<waitfor maxwait="${servlet.deploy.maxwait}"
timeoutproperty="servlet.deploy.error">
			<http url="${webserver.tests.url}" />
		</waitfor>

		<fail if="servlet.deploy.error">Unable to deploy servlet</fail>
	</target>



Any help I could get concerning this would be most appreciated.
Google, and posting and searching various java forums hasn't gotten me
any useful answers. For that matter, just letting me know if you've
had similar difficulties, or no difficulties with the same task would
be useful, as it'd give a hint as to whether I'm missing something
obvious. Thanks.

Mime
View raw message