SOLR-2002: add support for -Dtestmethod=xxx when running tests

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@983632 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Muir 2010-08-09 13:17:39 +00:00
parent 9d71710beb
commit 40a3eb4fd3
7 changed files with 54 additions and 0 deletions

View File

@ -53,6 +53,7 @@
</path>
<!-- default arguments to pass to JVM executing tests -->
<property name="testmethod" value=""/>
<property name="args" value=""/>
<property name="threadsPerProcessor" value="1" />
<property name="random.multiplier" value="1" />
@ -450,6 +451,8 @@
<sysproperty key="lucene.version" value="${dev.version}"/>
<sysproperty key="testmethod" value="${testmethod}"/>
<formatter type="xml"/>
<formatter classname="${junit.details.formatter}" usefile="false"/>
<batchtest fork="yes" todir="@{junit.output.dir}" if="runall">

View File

@ -30,6 +30,7 @@ import java.util.Collections;
import java.util.TimeZone;
import junit.framework.TestCase;
import junit.framework.TestResult;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.index.ConcurrentMergeScheduler;
@ -324,6 +325,14 @@ public abstract class LuceneTestCase extends TestCase {
}
}
@Override
public void run(TestResult result) {
if (LuceneTestCaseJ4.TEST_METHOD == null ||
getName().equals(LuceneTestCaseJ4.TEST_METHOD))
super.run(result);
}
@Override
public void runBare() throws Throwable {
//long t0 = System.currentTimeMillis();

View File

@ -44,7 +44,13 @@ import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestWatchman;
import org.junit.runner.Description;
import org.junit.runner.RunWith;
import org.junit.runner.manipulation.Filter;
import org.junit.runner.manipulation.NoTestsRemainException;
import org.junit.runners.BlockJUnit4ClassRunner;
import org.junit.runners.model.FrameworkMethod;
import org.junit.runners.model.InitializationError;
import java.io.File;
import java.io.PrintStream;
@ -101,6 +107,7 @@ import static org.junit.Assert.fail;
// every test. But the functionality we used to
// get from that override is provided by InterceptTestCaseEvents
//@RunWith(RunBareWrapper.class)
@RunWith(LuceneTestCaseJ4.LuceneTestCaseRunner.class)
public class LuceneTestCaseJ4 {
/**
@ -114,9 +121,16 @@ public class LuceneTestCaseJ4 {
*/
public static final Version TEST_VERSION_CURRENT = Version.LUCENE_40;
/**
* If this is set, it is the only method that should run.
*/
static final String TEST_METHOD;
/** Create indexes in this directory, optimally use a subdir, named after the test */
public static final File TEMP_DIR;
static {
String method = System.getProperty("testmethod", "").trim();
TEST_METHOD = method.length() == 0 ? null : method;
String s = System.getProperty("tempDir", System.getProperty("java.io.tmpdir"));
if (s == null)
throw new RuntimeException("To run tests, you need to define system property 'tempDir' or 'java.io.tmpdir'.");
@ -615,4 +629,27 @@ public class LuceneTestCaseJ4 {
private static final Random seedRnd = new Random();
private String name = "<unknown>";
/** optionally filters the tests to be run by TEST_METHOD */
public static class LuceneTestCaseRunner extends BlockJUnit4ClassRunner {
public LuceneTestCaseRunner(Class<?> clazz) throws InitializationError {
super(clazz);
Filter f = new Filter() {
@Override
public String describe() { return "filters according to TEST_METHOD"; }
@Override
public boolean shouldRun(Description d) {
return TEST_METHOD == null || d.getMethodName().equals(TEST_METHOD);
}
};
try {
f.apply(this);
} catch (NoTestsRemainException e) {
throw new RuntimeException(e);
}
}
}
}

View File

@ -445,6 +445,7 @@
<sysproperty key="tests.timezone" value="${tests.timezone}"/>
<sysproperty key="jetty.insecurerandom" value="1"/>
<sysproperty key="tempDir" file="@{tempDir}/@{threadNum}"/>
<sysproperty key="testmethod" value="${testmethod}"/>
<jvmarg line="${dir.prop}"/>
<jvmarg line="${args}"/>

View File

@ -109,6 +109,7 @@
<property name="build.javadoc.solrj" value="${build.docs}/api-solrj"/>
<!-- JUnit properties -->
<property name="testmethod" value=""/>
<property name="junit.includes" value="**/Test*.java,**/*Test.java"/>
<property name="junit.output.dir" location="${common-solr.dir}/${dest}/test-results"/>
<property name="junit.reports" location="${common-solr.dir}/${dest}/test-results/reports"/>

View File

@ -157,6 +157,7 @@
>
<sysproperty key="jetty.insecurerandom" value="1"/>
<sysproperty key="tempDir" file="${tempDir}"/>
<sysproperty key="testmethod" value="${testmethod}"/>
<formatter type="brief" usefile="false" if="junit.details"/>
<classpath refid="test.classpath"/>
<formatter type="xml"/>
@ -204,6 +205,7 @@
>
<sysproperty key="jetty.insecurerandom" value="1"/>
<sysproperty key="tempDir" file="${tempDir}"/>
<sysproperty key="testmethod" value="${testmethod}"/>
<formatter type="brief" usefile="false" if="junit.details"/>
<classpath refid="test.extras.classpath"/>
<assertions>

View File

@ -105,6 +105,7 @@
>
<sysproperty key="jetty.insecurerandom" value="1"/>
<sysproperty key="tempDir" file="${tempDir}"/>
<sysproperty key="testmethod" value="${testmethod}"/>
<formatter type="brief" usefile="false" if="junit.details"/>
<classpath refid="test.classpath"/>
<assertions>