Ignore nested test suites if run from IDEs.

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1308594 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Dawid Weiss 2012-04-02 22:03:30 +00:00
parent 983bc3bef1
commit 20bff30111
3 changed files with 24 additions and 9 deletions

View File

@ -23,7 +23,6 @@ import java.util.regex.Pattern;
import junit.framework.Assert;
import org.apache.lucene.util.LuceneTestCase;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
@ -51,7 +50,7 @@ public class TestExceptionInBeforeClassHooks extends WithNestedTests {
public void test() {}
}
public static class Nested2 extends LuceneTestCase {
public static class Nested2 extends WithNestedTests.AbstractNestedTest {
public void test1() throws Exception {
Thread t = new Thread() {
public void run() {

View File

@ -19,7 +19,6 @@ package org.apache.lucene.util.junitcompat;
import java.util.Properties;
import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.util.SystemPropertiesInvariantRule;
import org.apache.lucene.util.SystemPropertiesRestoreRule;
import org.junit.*;
@ -40,7 +39,7 @@ public class TestSystemPropertiesInvariantRule extends WithNestedTests {
super(true);
}
public static class Base extends LuceneTestCase {
public static class Base extends WithNestedTests.AbstractNestedTest {
public void testEmpty() {}
}
@ -102,6 +101,12 @@ public class TestSystemPropertiesInvariantRule extends WithNestedTests {
}
}
@Before
@After
public void cleanup() {
System.clearProperty(PROP_KEY1);
}
@Test
public void testRuleInvariantBeforeClass() {
Result runClasses = JUnitCore.runClasses(InBeforeClass.class);

View File

@ -24,8 +24,11 @@ import java.io.UnsupportedEncodingException;
import org.apache.lucene.util.LuceneTestCase;
import org.junit.After;
import org.junit.Assert;
import org.junit.Assume;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;
/**
* An abstract test class that prepares nested test classes to run.
@ -48,10 +51,18 @@ public abstract class WithNestedTests {
};
public static abstract class AbstractNestedTest extends LuceneTestCase {
@Before
public void before() {
Assume.assumeTrue(isRunningNested());
}
@ClassRule
public static TestRule ignoreIfRunAsStandalone = new TestRule() {
public Statement apply(final Statement s, Description arg1) {
return new Statement() {
public void evaluate() throws Throwable {
if (isRunningNested()) {
s.evaluate();
}
}
};
}
};
protected static boolean isRunningNested() {
return runsAsNested.get() != null && runsAsNested.get();