public abstract class LuceneTestCase extends Assert
 If you
 override either setUp() or
 tearDown() in your unit test, make sure you
 call super.setUp() and
 super.tearDown()
 
@After - replaces setup
 @Before - replaces teardown
 @Test - any public method with this annotation is a test case, regardless
 of its name
 
See Junit4 documentation for a complete list of features.
Import from org.junit rather than junit.framework.
You should be able to use this class anywhere you used LuceneTestCase if you annotate your derived class correctly with the annotations above
assertSaneFieldCaches(String)| Modifier and Type | Class and Description | 
|---|---|
| static interface  | LuceneTestCase.NightlyAnnotation for tests that should only be run during nightly builds. | 
| Modifier and Type | Field and Description | 
|---|---|
| static org.junit.rules.TestRule | classRulesThis controls how suite-level rules are nested. | 
| protected static SmartRandom | random | 
| static int | RANDOM_MULTIPLIERA random multiplier which you should use when writing random tests:
 multiply it by the number of iterations | 
| org.junit.rules.TestRule | ruleChainThis controls how individual test rules are nested. | 
| protected static Map<MockDirectoryWrapper,StackTraceElement[]> | stores | 
| static File | TEMP_DIRCreate indexes in this directory, optimally use a subdir, named after the test | 
| static String | TEST_CLEAN_THREADSwhether or not to clean threads between test invocations: "false", "perMethod", "perClass" | 
| static String | TEST_DIRECTORYGets the directory to run tests with | 
| static int | TEST_ITERGet the number of times to run tests | 
| static int | TEST_ITER_MINGet the minimum number of times to run tests until a failure happens | 
| static String | TEST_LINE_DOCS_FILEthe line file used by LineFileDocs | 
| static String | TEST_LOCALEGets the locale to run tests with | 
| static boolean | TEST_NIGHTLYwhether or not nightly tests should run | 
| static String | TEST_SEEDGet the random seed for tests | 
| static String | TEST_TIMEZONEGets the timezone to run tests with | 
| static org.apache.lucene.util.Version | TEST_VERSION_CURRENTUse this constant when creating Analyzers and any other version-dependent stuff. | 
| protected static boolean | testsFailed | 
| static boolean | VERBOSEtrue iff tests are run in verbose mode. | 
| Constructor and Description | 
|---|
| LuceneTestCase() | 
| Modifier and Type | Method and Description | 
|---|---|
| static void | afterClassLuceneTestCaseJ4() | 
| void | alwaysIgnoredTestMethod() | 
| static void | assertEquals(double expected,
            double actual)Deprecated.  | 
| static void | assertEquals(float expected,
            float actual)Deprecated.  | 
| static void | assertEquals(String message,
            double expected,
            double actual)Deprecated.  | 
| static void | assertEquals(String message,
            float expected,
            float actual)Deprecated.  | 
| protected void | assertSaneFieldCaches(String msg)Asserts that FieldCacheSanityChecker does not detect any
 problems with FieldCache.DEFAULT. | 
| static <T> Set<T> | asSet(T... args) | 
| static void | assumeFalse(String msg,
           boolean b) | 
| static void | assumeNoException(String msg,
                 Exception e) | 
| static void | assumeTrue(String msg,
          boolean b) | 
| static int | atLeast(int i) | 
| static int | atLeast(Random random,
       int i)Returns a number of at least  i | 
| static void | beforeClassLuceneTestCaseJ4() | 
| static void | dumpArray(String label,
         Object[] objs,
         PrintStream stream)Convenience method for logging an array. | 
| static void | dumpIterator(String label,
            Iterator<?> iter,
            PrintStream stream)Convenience method for logging an iterator. | 
| protected File | getDataFile(String name)Gets a resource from the classpath as  File. | 
| String | getName() | 
| static Class<?> | getTestClass()Return the current class being tested. | 
| protected String | getTestLabel() | 
| protected boolean | isTestThread()Returns true if and only if the calling thread is the primary thread 
 executing the test case. | 
| static Locale | localeForName(String localeName)return a Locale object equivalent to its programmatic name | 
| static MockDirectoryWrapper | newDirectory()Returns a new Directory instance. | 
| static MockDirectoryWrapper | newDirectory(org.apache.lucene.store.Directory d)Returns a new Directory instance, with contents copied from the
 provided directory. | 
| static MockDirectoryWrapper | newDirectory(Random r)Returns a new Directory instance, using the specified random. | 
| static MockDirectoryWrapper | newDirectory(Random r,
            org.apache.lucene.store.Directory d)Returns a new Directory instance, using the specified random
 with contents copied from the provided directory. | 
| static org.apache.lucene.document.Field | newField(Random random,
        String name,
        String value,
        org.apache.lucene.document.Field.Index index)Returns a new field instance, using the specified random. | 
| static org.apache.lucene.document.Field | newField(Random random,
        String name,
        String value,
        org.apache.lucene.document.Field.Store store,
        org.apache.lucene.document.Field.Index index)Returns a new field instance, using the specified random. | 
| static org.apache.lucene.document.Field | newField(Random random,
        String name,
        String value,
        org.apache.lucene.document.Field.Store store,
        org.apache.lucene.document.Field.Index index,
        org.apache.lucene.document.Field.TermVector tv)Returns a new field instance, using the specified random. | 
| static org.apache.lucene.document.Field | newField(String name,
        String value,
        org.apache.lucene.document.Field.Index index)Returns a new field instance. | 
| static org.apache.lucene.document.Field | newField(String name,
        String value,
        org.apache.lucene.document.Field.Store store,
        org.apache.lucene.document.Field.Index index)Returns a new field instance. | 
| static org.apache.lucene.document.Field | newField(String name,
        String value,
        org.apache.lucene.document.Field.Store store,
        org.apache.lucene.document.Field.Index index,
        org.apache.lucene.document.Field.TermVector tv)Returns a new Field instance. | 
| static MockDirectoryWrapper | newFSDirectory(File f)Returns a new FSDirectory instance over the given file, which must be a folder. | 
| static MockDirectoryWrapper | newFSDirectory(File f,
              org.apache.lucene.store.LockFactory lf)Returns a new FSDirectory instance over the given file, which must be a folder. | 
| static org.apache.lucene.index.IndexWriterConfig | newIndexWriterConfig(Random r,
                    org.apache.lucene.util.Version v,
                    org.apache.lucene.analysis.Analyzer a)create a new index writer config with random defaults using the specified random | 
| static org.apache.lucene.index.IndexWriterConfig | newIndexWriterConfig(org.apache.lucene.util.Version v,
                    org.apache.lucene.analysis.Analyzer a)create a new index writer config with random defaults | 
| static org.apache.lucene.index.LogMergePolicy | newLogMergePolicy() | 
| static org.apache.lucene.index.LogMergePolicy | newLogMergePolicy(boolean useCFS) | 
| static org.apache.lucene.index.LogMergePolicy | newLogMergePolicy(boolean useCFS,
                 int mergeFactor) | 
| static org.apache.lucene.index.LogMergePolicy | newLogMergePolicy(int mergeFactor) | 
| static org.apache.lucene.index.LogMergePolicy | newLogMergePolicy(Random r) | 
| static org.apache.lucene.search.IndexSearcher | newSearcher(org.apache.lucene.index.IndexReader r)create a new searcher over the reader. | 
| static org.apache.lucene.search.IndexSearcher | newSearcher(org.apache.lucene.index.IndexReader r,
           boolean maybeWrap)create a new searcher over the reader. | 
| static org.apache.lucene.index.TieredMergePolicy | newTieredMergePolicy() | 
| static org.apache.lucene.index.TieredMergePolicy | newTieredMergePolicy(Random r) | 
| protected void | purgeFieldCache(org.apache.lucene.search.FieldCache fc)Forcible purges all cache entries from the FieldCache. | 
| static String | randomDirectory(Random random) | 
| static Locale | randomLocale(Random random)return a random Locale from the available locales on the system | 
| static TimeZone | randomTimeZone(Random random)return a random TimeZone from the available timezones on the system | 
| static boolean | rarely() | 
| static boolean | rarely(Random random)Returns true if something should happen rarely, | 
| void | reportAdditionalFailureInfo() | 
| static void | reportPartialFailureInfo() | 
| static void | setMergeFactor(org.apache.lucene.index.MergePolicy mp,
              int mergeFactor) | 
| void | setUp()For subclassing only. | 
| static void | setUseCompoundFile(org.apache.lucene.index.MergePolicy mp,
                  boolean useCompound) | 
| void | tearDown()For subclassing only. | 
| static boolean | usually() | 
| static boolean | usually(Random random) | 
assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertThat, assertThat, assertTrue, assertTrue, fail, failpublic static final boolean VERBOSE
public static final org.apache.lucene.util.Version TEST_VERSION_CURRENT
NOTE: Change this when development starts for new Lucene version:
public static final File TEMP_DIR
public static final String TEST_LOCALE
public static final String TEST_TIMEZONE
public static final String TEST_DIRECTORY
public static final int TEST_ITER
public static final int TEST_ITER_MIN
public static final String TEST_SEED
public static final boolean TEST_NIGHTLY
public static final String TEST_LINE_DOCS_FILE
public static final String TEST_CLEAN_THREADS
public static final int RANDOM_MULTIPLIER
protected static Map<MockDirectoryWrapper,StackTraceElement[]> stores
public static org.junit.rules.TestRule classRules
LuceneTestCase are executed in proper order if they depend on each 
 other.public final org.junit.rules.TestRule ruleChain
LuceneTestCase are executed in proper order if they depend on each 
 other.protected static boolean testsFailed
protected static final SmartRandom random
public static void beforeClassLuceneTestCaseJ4()
public static void afterClassLuceneTestCaseJ4()
protected void purgeFieldCache(org.apache.lucene.search.FieldCache fc)
This method will be called by tearDown to clean up FieldCache.DEFAULT. If a (poorly written) test has some expectation that the FieldCache will persist across test methods (ie: a static IndexReader) this method can be overridden to do nothing.
FieldCache.purgeAllCaches()protected String getTestLabel()
public static void setUseCompoundFile(org.apache.lucene.index.MergePolicy mp,
                      boolean useCompound)
public static void setMergeFactor(org.apache.lucene.index.MergePolicy mp,
                  int mergeFactor)
protected boolean isTestThread()
public void setUp()
           throws Exception
super.setUp().Exceptionpublic void tearDown()
              throws Exception
super.tearDown().Exceptionprotected void assertSaneFieldCaches(String msg)
If any problems are found, they are logged to System.err (allong with the msg) when the Assertion is thrown.
This method is called by tearDown after every test method, however IndexReaders scoped inside test methods may be garbage collected prior to this method being called, causing errors to be overlooked. Tests are encouraged to keep their IndexReaders scoped at the class level, or to explicitly call this method directly in the same scope as the IndexReader.
FieldCacheSanityCheckerpublic static int atLeast(Random random, int i)
i
 
 The actual number returned will be influenced by whether TEST_NIGHTLY
 is active and RANDOM_MULTIPLIER, but also with some random fudge.
public static int atLeast(int i)
public static boolean rarely(Random random)
 The actual number returned will be influenced by whether TEST_NIGHTLY
 is active and RANDOM_MULTIPLIER.
public static boolean rarely()
public static boolean usually(Random random)
public static boolean usually()
@Deprecated public static void assertEquals(double expected, double actual)
@Deprecated public static void assertEquals(String message, double expected, double actual)
@Deprecated public static void assertEquals(float expected, float actual)
@Deprecated public static void assertEquals(String message, float expected, float actual)
public static void assumeTrue(String msg, boolean b)
public static void assumeFalse(String msg, boolean b)
public static <T> Set<T> asSet(T... args)
public static void dumpIterator(String label, Iterator<?> iter, PrintStream stream)
label - String logged before/after the items in the iteratoriter - Each next() is toString()ed and logged on it's own line. If iter is null this is logged differnetly then an empty iterator.stream - Stream to log messages to.public static void dumpArray(String label, Object[] objs, PrintStream stream)
public static org.apache.lucene.index.IndexWriterConfig newIndexWriterConfig(org.apache.lucene.util.Version v,
                                                             org.apache.lucene.analysis.Analyzer a)
public static org.apache.lucene.index.IndexWriterConfig newIndexWriterConfig(Random r, org.apache.lucene.util.Version v, org.apache.lucene.analysis.Analyzer a)
public static org.apache.lucene.index.LogMergePolicy newLogMergePolicy()
public static org.apache.lucene.index.TieredMergePolicy newTieredMergePolicy()
public static org.apache.lucene.index.LogMergePolicy newLogMergePolicy(Random r)
public static org.apache.lucene.index.TieredMergePolicy newTieredMergePolicy(Random r)
public static org.apache.lucene.index.LogMergePolicy newLogMergePolicy(boolean useCFS)
public static org.apache.lucene.index.LogMergePolicy newLogMergePolicy(boolean useCFS,
                                                       int mergeFactor)
public static org.apache.lucene.index.LogMergePolicy newLogMergePolicy(int mergeFactor)
public static MockDirectoryWrapper newDirectory() throws IOException
 The Directory is wrapped with MockDirectoryWrapper.
 By default this means it will be picky, such as ensuring that you
 properly close it and all open files in your test. It will emulate
 some features of Windows, such as not allowing open files to be
 overwritten.
IOExceptionpublic static MockDirectoryWrapper newDirectory(Random r) throws IOException
newDirectory() for more information.IOExceptionpublic static MockDirectoryWrapper newDirectory(org.apache.lucene.store.Directory d) throws IOException
newDirectory() for more
 information.IOExceptionpublic static MockDirectoryWrapper newFSDirectory(File f) throws IOException
IOExceptionpublic static MockDirectoryWrapper newFSDirectory(File f, org.apache.lucene.store.LockFactory lf) throws IOException
IOExceptionpublic static MockDirectoryWrapper newDirectory(Random r, org.apache.lucene.store.Directory d) throws IOException
newDirectory() for more information.IOExceptionpublic static org.apache.lucene.document.Field newField(String name, String value, org.apache.lucene.document.Field.Index index)
newField(String, String, Field.Store, Field.Index, Field.TermVector) for more informationpublic static org.apache.lucene.document.Field newField(String name, String value, org.apache.lucene.document.Field.Store store, org.apache.lucene.document.Field.Index index)
newField(String, String, Field.Store, Field.Index, Field.TermVector) for more informationpublic static org.apache.lucene.document.Field newField(String name, String value, org.apache.lucene.document.Field.Store store, org.apache.lucene.document.Field.Index index, org.apache.lucene.document.Field.TermVector tv)
public static org.apache.lucene.document.Field newField(Random random, String name, String value, org.apache.lucene.document.Field.Index index)
newField(String, String, Field.Store, Field.Index, Field.TermVector) for more informationpublic static org.apache.lucene.document.Field newField(Random random, String name, String value, org.apache.lucene.document.Field.Store store, org.apache.lucene.document.Field.Index index)
newField(String, String, Field.Store, Field.Index, Field.TermVector) for more informationpublic static org.apache.lucene.document.Field newField(Random random, String name, String value, org.apache.lucene.document.Field.Store store, org.apache.lucene.document.Field.Index index, org.apache.lucene.document.Field.TermVector tv)
newField(String, String, Field.Store, Field.Index, Field.TermVector) for more informationpublic static Locale randomLocale(Random random)
public static TimeZone randomTimeZone(Random random)
public static Locale localeForName(String localeName)
public static org.apache.lucene.search.IndexSearcher newSearcher(org.apache.lucene.index.IndexReader r)
                                                          throws IOException
IOExceptionpublic static org.apache.lucene.search.IndexSearcher newSearcher(org.apache.lucene.index.IndexReader r,
                                                 boolean maybeWrap)
                                                          throws IOException
maybeWrap is true, this searcher might wrap the reader
 with one that returns null for getSequentialSubReaders.IOExceptionpublic String getName()
protected File getDataFile(String name) throws IOException
File. This method should only be used,
 if a real file is needed. To get a stream, code should prefer
 Class.getResourceAsStream(java.lang.String) using this.getClass().IOExceptionpublic static void reportPartialFailureInfo()
public void reportAdditionalFailureInfo()
public static Class<?> getTestClass()
public final void alwaysIgnoredTestMethod()