Bugzilla – Bug 3668
A way to run just one TestCase
Last modified: 2005-09-16 15:50:34
You need to log in before you can comment on or make changes to this bug.
To isolate a problem it was necessary to run just one TestCase from RFTTest.java. I found the approach documented here to be very useful: http://today.java.net/pub/a/today/2003/09/12/individual-test-cases.html This is the syntax to run just one test(in this case testDirTransfer): ant run_one -Dtests.jar=/opt/gt401f/lib/globus_wsrf_rft_test.jar -f /opt/gt401f/share/globus_wsrf_rft_test/runtests.xml -Dtest=RFTTest.class -Dtests=testDirTransfer If you take the java code from TestUtils (which i renamed to TestUtil) and add these headers, it will compile: package org.globus.transfer.reliable.service.test; import junit.framework.TestCase; import junit.framework.TestSuite; import java.util.StringTokenizer; import java.util.ArrayList; import java.util.List; import java.util.Iterator; import java.lang.reflect.Constructor; import java.lang.Object; Then change the rft PackageTests suite method: public static Test suite() throws Exception { TestSuite suite = new PackageTests( "RFT Testing" ); if ( TestUtil.hasTestCases() ) { return TestUtil.getSuite( RFTTest.class ); } suite.addTest( new TestSuite( RFTTest.class ) ); suite.addTest( new TestSuite( RFTOptionsTest.class ) ); return suite; } Then change share/globus_wsrf_rft_test/runtests.xml - add the following targets: <target name="_ensure-test-name" unless="test"> <fail message="You must run this target with -Dtest=TestName"/> </target> <target name="_runtest" description="Runs the test you specify on the command line with -Dtest=" depends="_ensure-test-name"> <junit printsummary="withOutAndErr" fork="yes"> <sysproperty key="tests" value="${tests}"/> <sysproperty key="org.globus.wsrf.container.webroot" value="${abs.deploy.dir}"/> <sysproperty key="GLOBUS_LOCATION" value="${abs.deploy.dir}"/> <sysproperty key="package.name" value="${ant.project.name}"/> <classpath> <pathelement location="${abs.deploy.dir}"/> <fileset dir="${abs.deploy.dir}/lib"> <include name="*.jar"/> </fileset> </classpath> <formatter type="plain" usefile="false"/> <batchtest> <fileset dir="${tests.dir}"> <patternset refid="test.fileset"/> </fileset> </batchtest> </junit> </target> <target name="run_one" description="Executes tests contained in a jar file (in external container)" depends="init"> <property name="server.arg" value="-Dignore" /> <antcall target="runTests_one"/> </target> <target name="runTests_one" unless="securityTestsOnly"> <patternset id="package.fileset"> <include name="**/PackageTests.class" /> </patternset> <antcall target="_runtest"> <reference refid="package.fileset" torefid="test.fileset"/> </antcall> </target> Comments: 1) The ant targets are basically a copy of the current targets (like runCustomTests) combined with the targets from the article. I'm sure some combination could be made to reduce redundancy. 2) I imagine that TestUtil could be improved/added to and some targets adjusted such that there would be no need to code a PackageTest at all. But the approach documented here at least doesn't impact any existing processes or documentation. 3) You may not want TestUtil to be in the reliable.service.test package. 4) I do like the plain formatter and the fact that it dumps to output to stdout in this case. Seems like the correct output options when you are running one TestCase.
We're going to consider adding this to the core testing framework.
I added support for running a specific set of test cases at a time. It's part of the Java WS Core testing framework. The new test targets are called 'runOne' and 'runOneServer'. Both take the same arguements: 1) '-Dtest.class=<class name>' - specifies the class that has the test suite. It's required. 2) '-Dtests=<testCase1[,testCaseN]>' - specifies a set of specific test cases to execute (comma-separated list). It is optional. If not specified, all tests cases are executed. Example: > cd $GLOBUS_LOCATION > ant -f share\globus_wsrf_test\runtests.xml runOne -Dtest.class=org.globus.transfer.reliable.service.test.PackageTests -Dtests=testDirTransfer This will work properly if the org.globus.wsrf.test.FilteredTestSuite is used instead of the junit.framework.TestSuite. GridTestSuite now inherits from the FilteredTestSuite. Not everything has been updated yet to use the new FilteredTestSuite.