Namespace Lucene.Net.Util
Classes
AbstractBeforeAfterRule
LUCENENET specific for mimicking the JUnit rule functionality. We simplify things by just running the rules inside LuceneTestCase.
ApiScanTestBase
LUCENENET specific - functionality for scanning the API to ensure naming and .NET conventions are followed consistently. Not for use by end users.
BaseDocIdSetTestCase<T>
Base test class for Lucene.Net.Search.DocIdSets.
DefaultNamespaceTypeWrapper
The TypeWrapper class wraps a Type so it may be used in
a platform-independent manner. This class overrides the
namespace to return null
so it is only run once per
assembly.
English
Converts numbers to english strings for testing.
Note
This API is for internal purposes only and might change in incompatible ways in the next release.
FailOnNonBulkMergesInfoStream
Hackidy-Häck-Hack to cause a test to fail on non-bulk merges
LineFileDocs
Minimal port of benchmark's LneDocSource + DocMaker, so tests can enum docs from a line file created by benchmark's WriteLineDoc task
LuceneTestCase
Base class for all Lucene.Net unit tests.
Class and instance setup.
The preferred way to specify class (suite-level) setup/cleanup is to use static methods annotated with NUnit.Framework.OneTimeSetUpAttribute and NUnit.Framework.OneTimeTearDownAttribute. Any code in these methods is executed within the test framework's control and ensure proper setup has been made. Try not to use static initializers (including complex readonly field initializers). Static initializers are executed before any setup rules are fired and may cause you (or somebody else) headaches.
For instance-level setup, use NUnit.Framework.SetUpAttribute and NUnit.Framework.TearDownAttribute annotated
methods. If you override either SetUp() or TearDown() in
your subclass, make sure you call base.SetUp()
and
base.TearDown()
. This is detected and enforced.
Specifying test cases
Any test method annotated with NUnit.Framework.TestAttribute is considered a test case.
Randomized execution and test facilities
LuceneTestCase uses a custom LuceneTestCase.TestFixtureAttribute to execute test cases. The custom LuceneTestCase.TestFixtureAttribute has built-in support for test randomization including access to a repeatable Random instance. See Random property. Any test using Random acquired from Random should be fully reproducible (assuming no race conditions between threads etc.). The initial seed for a test case is reported in the failure test message.
The seed can be configured with a RunSettings file, a lucene.testSettings.config
JSON file,
an environment variable, or using RandomSeedAttribute at the assembly level.
It is recommended to configure the culture also, since they are randomly picked from a list
of cultures installed on a given machine, so the culture will vary from one machine to the next.
.runsettings File Configuration Example
<RunSettings>
<TestRunParameters>
<Parameter name="tests:seed" value="0x1ffa1d067056b0e6" />
<Parameter name="tests:culture" value="sw-TZ" />
</TestRunParameters>
</RunSettings>
See the .runsettings documentation at: https://docs.microsoft.com/en-us/visualstudio/test/configure-unit-tests-by-using-a-dot-runsettings-file.
Attribute Configuration Example
[assembly: Lucene.Net.Util.RandomSeed("0x1ffa1d067056b0e6")]
[assembly: NUnit.Framework.SetCulture("sw-TZ")]
lucene.testSettings.config File Configuration Example
Add a file named lucene.testSettings.config to the executable directory or any directory between the executable and the root of the drive with the following contents.
{
"tests": {
"seed": "0x1ffa1d067056b0e6",
"culture": "sw-TZ"
}
}
Environment Variable Configuration Example
Variable | Value |
---|---|
lucene:tests:seed | 0x1ffa1d067056b0e6 |
lucene:tests:culture | sw-TZ |
LuceneTestCase.AwaitsFixAttribute
Attribute for tests which exhibit a known issue and are temporarily disabled.
LuceneTestCase.NightlyAttribute
Attribute for tests that should only be run during nightly builds.
LuceneTestCase.SlowAttribute
Attribute for tests that are slow. Slow tests do run by default but can be disabled if a quick run is needed.
LuceneTestCase.SuppressCodecsAttribute
Attribute for test classes that should avoid certain codec types (because they are expensive, for example).
LuceneTestCase.SuppressTempFileChecksAttribute
Marks any suites which are known not to close all the temporary files. This may prevent temp files and folders from being cleaned up after the suite is completed.
LuceneTestCase.TestFixtureAttribute
Marks the class as a TestFixture.
LuceneTestCase.WeeklyAttribute
Attribute for tests that should only be run during weekly builds.
LuceneTestFrameworkInitializer
LuceneTestFrameworkInitializer may be subclassed in order to use standard dependency injection techniques for classes under test. A subclass of LuceneTestFrameworkInitializer will be executed automatically.
Only one subclass per assembly is allowed, and by convention these subclasses are usually named "Startup".
The following abstract factories can be overridden for testing purposes:
Abstraction | Factory Method Name | Default |
---|---|---|
Lucene.Net.Codecs.ICodecFactory | CodecFactory | TestCodecFactory |
Lucene.Net.Codecs.IDocValuesFormatFactory | DocValuesFormatFactory | TestDocValuesFormatFactory |
Lucene.Net.Codecs.IPostingsFormatFactory | PostingsFormatFactory | TestPostingsFormatFactory |
Lucene.Net.Configuration.IConfigurationFactory | ConfigurationFactory | Lucene.Net.Configuration.TestConfigurationFactory |
Methods are executed one time per assembly, and are executed in the following order:
Method | Description |
---|---|
Initialize() | Used to set the factories in the above table. In general, dependency injection for the test assembly is setup in this method. No randomized context is available. |
TestFrameworkSetUp() | Used to set assembly-level test setup. Executed before all tests and class-level setup in the assembly. Repeatable randomized content can be generated using the Random property. |
TestFrameworkTearDown() | Used to tear down assembly-level test setup. Executed after all tests and class-level tear down in the assembly. Repeatable randomized content can be generated using the Random property. |
Example:
using RandomizedTesting.Generators;
public class Startup : LuceneTestFrameworkInitializer
{
// Run first
protected override void Initialize()
{
// Inject a custom configuration factory
ConfigurationFactory = new MyConfigurationFactory();
// Do any additional dependency injection setup here
}
// Run before all tests in the assembly and before any class-level setup
protected overide void TestFrameworkSetUp()
{
// Get the random instance for the current context
var random = Random;
// Generate random content
string content = random.NextSimpleString();
// Use randomization from LuceneTestCase
int numberOfDocuments = LuceneTestCase.AtLeast(30);
}
// Run after all tests in the assembly and after any class-level setup
protected override void TestFrameworkTearDown()
{
// Tear down everything here
}
}
NullInfoStream
Prints nothing. Just to make sure tests pass w/ and without enabled Lucene.Net.Util.InfoStream without actually making noise.
Note
This API is experimental and might change in incompatible ways in the next release.
RandomSeedAttribute
Specifies a random seed to use when running tests. This allows specific test conditions to be repeated for debugging purposes.
StackTraceHelper
LUCENENET specific class to normalize stack trace behavior between different .NET Framework and .NET Standard 1.x, which did not support the StackTrace class.
TestUtil
General utility methods for Lucene unit tests.
ThrottledIndexOutput
Intentionally slow Lucene.Net.Store.IndexOutput for testing.
TimeUnits
Time unit constants for use in annotations.
UseTempLineDocsFileAttribute
Specifies to extract the LineFileDocs to a temp directory and use the same file for the entire assembly. The file path can be obtained from the to TestLineDocsFile property.