public class RandomizedTest
extends java.lang.Object
Listeners,
RandomizedContext| Modifier and Type | Field and Description |
|---|---|
protected static java.nio.charset.Charset |
ISO8859_1 |
static java.lang.String |
SYSPROP_MULTIPLIER
The global multiplier property (Double).
|
protected static java.nio.charset.Charset |
US_ASCII |
protected static java.nio.charset.Charset |
UTF16 |
protected static java.nio.charset.Charset |
UTF32 |
protected static java.nio.charset.Charset |
UTF8 |
| Constructor and Description |
|---|
RandomizedTest() |
| Modifier and Type | Method and Description |
|---|---|
static java.lang.Object[] |
$(java.lang.Object... objects)
This is an absolutely hacky utility to take a vararg as input and return the array
of arguments as output.
|
static java.lang.Object[][] |
$$(java.lang.Object[]... objects) |
static void |
assumeFalse(boolean condition)
Reverse of
assumeTrue(boolean). |
static void |
assumeFalse(java.lang.String message,
boolean condition)
Reverse of
assumeTrue(String, boolean). |
static void |
assumeNoException(java.lang.String msg,
java.lang.Throwable t)
Assume
t is null. |
static void |
assumeNoException(java.lang.Throwable t)
Making
Assume.assumeNoException(Throwable) directly available. |
static void |
assumeNotNull(java.lang.Object... objects)
Making
Assume.assumeNotNull(Object...) directly available. |
static void |
assumeTrue(boolean condition)
Making
Assume.assumeTrue(boolean) directly available. |
static void |
assumeTrue(java.lang.String message,
boolean condition) |
static int |
atLeast(int min)
Returns a random value greater or equal to
min. |
static int |
atMost(int max)
Returns a non-negative random value smaller or equal
max. |
static int |
between(int min,
int max)
An alias for
randomIntBetween(int, int). |
static long |
between(long min,
long max)
An alias for
randomLongBetween(long, long). |
static double |
biasedDoubleBetween(double min,
double max)
A biased "evil" random double between min and max (inclusive).
|
static float |
biasedFloatBetween(float min,
float max)
A biased "evil" random float between min and max (inclusive).
|
static <T extends java.io.Closeable> |
closeAfterSuite(T resource)
Registers a
Closeable resource that should be closed after the suite
completes. |
<T extends java.io.Closeable> |
closeAfterTest(T resource)
Registers a
Closeable resource that should be closed after the test
completes. |
static boolean |
frequently()
The exact opposite of
rarely(). |
static RandomizedContext |
getContext()
Shortcut for
RandomizedContext.current(). |
static java.util.Random |
getRandom()
Shortcut for
RandomizedContext.getRandom(). |
static java.nio.file.Path |
globalTempDir()
Global temporary directory created for the duration of this class's lifespan.
|
static boolean |
isNightly()
Returns true if
Nightly test group is enabled. |
static int |
iterations(int min,
int max)
Returns a "scaled" number of iterations for loops which can have a variable
iteration count.
|
static double |
multiplier()
A multiplier can be used to linearly scale certain values.
|
static java.net.ServerSocket |
newServerSocket(LifecycleScope scope)
Assign a temporary server socket.
|
java.nio.file.Path |
newTempDir()
Creates a new temporary directory for the
LifecycleScope.TEST duration. |
static java.nio.file.Path |
newTempDir(LifecycleScope scope)
Creates a temporary directory, deleted after the given lifecycle phase.
|
java.nio.file.Path |
newTempFile()
Creates a new temporary file for the
LifecycleScope.TEST duration. |
static java.nio.file.Path |
newTempFile(LifecycleScope scope)
Creates a new temporary file deleted after the given lifecycle phase completes.
|
protected static java.lang.String |
nextTempName()
Next temporary filename.
|
static java.lang.String |
randomAsciiAlphanumOfLength(int codeUnits) |
static java.lang.String |
randomAsciiAlphanumOfLengthBetween(int minCodeUnits,
int maxCodeUnits) |
static java.lang.String |
randomAsciiLettersOfLength(int codeUnits) |
static java.lang.String |
randomAsciiLettersOfLengthBetween(int minLetters,
int maxLetters) |
static java.lang.String |
randomAsciiOfLength(int codeUnits)
Deprecated.
Use
randomAsciiLettersOfLength(int) instead. |
static java.lang.String |
randomAsciiOfLengthBetween(int minCodeUnits,
int maxCodeUnits)
Deprecated.
Use
randomAsciiLettersOfLengthBetween(int, int) instead. |
static boolean |
randomBoolean() |
static byte |
randomByte() |
static byte[] |
randomBytesOfLength(int length)
Returns a byte array with random content.
|
static byte[] |
randomBytesOfLength(int minLength,
int maxLength)
Returns a byte array with random content.
|
static double |
randomDouble() |
static float |
randomFloat() |
static byte |
randomFrom(byte[] array) |
static char |
randomFrom(char[] array) |
static double |
randomFrom(double[] array) |
static float |
randomFrom(float[] array) |
static int |
randomFrom(int[] array) |
static <T> T |
randomFrom(java.util.List<T> list)
Pick a random object from the given list.
|
static long |
randomFrom(long[] array) |
static short |
randomFrom(short[] array) |
static <T> T |
randomFrom(T[] array)
Pick a random object from the given array.
|
static double |
randomGaussian() |
static int |
randomInt() |
static int |
randomInt(int max)
Deprecated.
|
static int |
randomIntBetween(int min,
int max)
A random integer from
min to max (inclusive). |
static java.util.Locale |
randomLocale()
Return a random Locale from the available locales on the system.
|
static long |
randomLong() |
static long |
randomLong(long max)
Deprecated.
|
static long |
randomLongBetween(long min,
long max)
A random long from
min to max (inclusive). |
static java.lang.String |
randomRealisticUnicodeOfCodepointLength(int codePoints) |
static java.lang.String |
randomRealisticUnicodeOfCodepointLengthBetween(int minCodePoints,
int maxCodePoints) |
static java.lang.String |
randomRealisticUnicodeOfLength(int codeUnits) |
static java.lang.String |
randomRealisticUnicodeOfLengthBetween(int minCodeUnits,
int maxCodeUnits) |
static short |
randomShort() |
static java.util.TimeZone |
randomTimeZone()
Return a random TimeZone from the available timezones on the system.
|
static java.lang.String |
randomUnicodeOfCodepointLength(int codePoints) |
static java.lang.String |
randomUnicodeOfCodepointLengthBetween(int minCodePoints,
int maxCodePoints) |
static java.lang.String |
randomUnicodeOfLength(int codeUnits) |
static java.lang.String |
randomUnicodeOfLengthBetween(int minCodeUnits,
int maxCodeUnits) |
static boolean |
rarely()
Rarely returns
true in about 10% of all calls (regardless of the
isNightly() mode). |
static void |
rmDir(java.nio.file.Path path)
Recursively delete a folder.
|
static int |
scaledRandomIntBetween(int min,
int max)
Returns a "scaled" random number between min and max (inclusive).
|
static void |
sleep(long millis)
Same as
Thread.sleep(long). |
static boolean |
systemPropertyAsBoolean(java.lang.String propertyName,
boolean defaultValue)
Get a system property and convert it to a boolean, if defined.
|
static double |
systemPropertyAsDouble(java.lang.String propertyName,
double defaultValue)
Get a system property and convert it to a double, if defined.
|
static float |
systemPropertyAsFloat(java.lang.String propertyName,
float defaultValue)
Get a system property and convert it to a float, if defined.
|
static int |
systemPropertyAsInt(java.lang.String propertyName,
int defaultValue)
Get a system property and convert it to an int, if defined.
|
static float |
systemPropertyAsLong(java.lang.String propertyName,
int defaultValue)
Get a system property and convert it to a long, if defined.
|
public static final java.lang.String SYSPROP_MULTIPLIER
multiplier(),
Constant Field Valuesprotected static final java.nio.charset.Charset UTF8
protected static final java.nio.charset.Charset UTF16
protected static final java.nio.charset.Charset ISO8859_1
protected static final java.nio.charset.Charset US_ASCII
protected static final java.nio.charset.Charset UTF32
public static RandomizedContext getContext()
RandomizedContext.current().public static boolean isNightly()
Nightly test group is enabled.Nightlypublic static java.util.Random getRandom()
RandomizedContext.getRandom(). Even though this method
is static, it returns per-thread Random instance, so no race conditions
can occur.
It is recommended that specific methods are used to pick random values.
public static boolean randomBoolean()
public static byte randomByte()
public static short randomShort()
public static int randomInt()
public static float randomFloat()
public static double randomDouble()
public static long randomLong()
public static double randomGaussian()
Random.nextGaussian()public static float biasedFloatBetween(float min,
float max)
public static double biasedDoubleBetween(double min,
double max)
public static byte[] randomBytesOfLength(int length)
length - The length of the byte array. Can be zero.public static byte[] randomBytesOfLength(int minLength,
int maxLength)
minLength - The minimum length of the byte array. Can be zero.maxLength - The maximum length of the byte array. Can be zero.@Deprecated public static int randomInt(int max)
@Deprecated public static long randomLong(long max)
public static int randomIntBetween(int min,
int max)
min to max (inclusive).scaledRandomIntBetween(int, int)public static int between(int min,
int max)
randomIntBetween(int, int).scaledRandomIntBetween(int, int)public static long randomLongBetween(long min,
long max)
min to max (inclusive).public static long between(long min,
long max)
randomLongBetween(long, long).public static int atLeast(int min)
min. The value
picked is affected by isNightly() and multiplier().scaledRandomIntBetween(int, int)public static int atMost(int max)
max. The value
picked is affected by isNightly() and multiplier().
This method is effectively an alias to:
scaledRandomIntBetween(0, max)
scaledRandomIntBetween(int, int)public static boolean rarely()
true in about 10% of all calls (regardless of the
isNightly() mode).public static boolean frequently()
rarely().public static <T> T randomFrom(T[] array)
public static <T> T randomFrom(java.util.List<T> list)
public static byte randomFrom(byte[] array)
public static short randomFrom(short[] array)
public static int randomFrom(int[] array)
public static char randomFrom(char[] array)
public static float randomFrom(float[] array)
public static long randomFrom(long[] array)
public static double randomFrom(double[] array)
public static double multiplier()
The default multiplier value is 1.
SYSPROP_MULTIPLIERpublic static int iterations(int min,
int max)
scaledRandomIntBetween(int, int).public static int scaledRandomIntBetween(int min,
int max)
min - Minimum (inclusive).max - Maximum (inclusive).multiplier()public static java.nio.file.Path globalTempDir()
throws java.io.IOException
java.io.IOExceptionpublic java.nio.file.Path newTempDir()
throws java.io.IOException
LifecycleScope.TEST duration.java.io.IOExceptionglobalTempDir()public static java.nio.file.Path newTempDir(LifecycleScope scope) throws java.io.IOException
java.io.IOExceptionpublic <T extends java.io.Closeable> T closeAfterTest(T resource)
Closeable resource that should be closed after the test
completes.resource (for call chaining).public static <T extends java.io.Closeable> T closeAfterSuite(T resource)
Closeable resource that should be closed after the suite
completes.resource (for call chaining).public java.nio.file.Path newTempFile()
throws java.io.IOException
LifecycleScope.TEST duration.java.io.IOExceptionpublic static java.nio.file.Path newTempFile(LifecycleScope scope) throws java.io.IOException
java.io.IOExceptionprotected static java.lang.String nextTempName()
public static void rmDir(java.nio.file.Path path)
throws java.io.IOException
path - Path to the folder to be (recursively) deleted. The folder must
exist.java.io.IOExceptionpublic static java.net.ServerSocket newServerSocket(LifecycleScope scope) throws java.io.IOException
scope - The lifecycle scope to close the socket after. If the socket is
closed earlier, nothing happens (silently dropped).java.io.IOExceptionpublic static java.util.Locale randomLocale()
Warning: This test assumes the returned array of locales is repeatable from jvm execution to jvm execution. It _may_ be different from jvm to jvm and as such, it can render tests execute in a different way.
public static java.util.TimeZone randomTimeZone()
Warning: This test assumes the returned array of time zones is repeatable from jvm execution to jvm execution. It _may_ be different from jvm to jvm and as such, it can render tests execute in a different way.
@Deprecated
public static java.lang.String randomAsciiOfLengthBetween(int minCodeUnits,
int maxCodeUnits)
randomAsciiLettersOfLengthBetween(int, int) instead.@Deprecated public static java.lang.String randomAsciiOfLength(int codeUnits)
randomAsciiLettersOfLength(int) instead.public static java.lang.String randomAsciiLettersOfLengthBetween(int minLetters,
int maxLetters)
public static java.lang.String randomAsciiLettersOfLength(int codeUnits)
public static java.lang.String randomAsciiAlphanumOfLengthBetween(int minCodeUnits,
int maxCodeUnits)
public static java.lang.String randomAsciiAlphanumOfLength(int codeUnits)
public static java.lang.String randomUnicodeOfLengthBetween(int minCodeUnits,
int maxCodeUnits)
public static java.lang.String randomUnicodeOfLength(int codeUnits)
public static java.lang.String randomUnicodeOfCodepointLengthBetween(int minCodePoints,
int maxCodePoints)
public static java.lang.String randomUnicodeOfCodepointLength(int codePoints)
public static java.lang.String randomRealisticUnicodeOfLengthBetween(int minCodeUnits,
int maxCodeUnits)
public static java.lang.String randomRealisticUnicodeOfLength(int codeUnits)
public static java.lang.String randomRealisticUnicodeOfCodepointLengthBetween(int minCodePoints,
int maxCodePoints)
public static java.lang.String randomRealisticUnicodeOfCodepointLength(int codePoints)
public static java.lang.Object[] $(java.lang.Object... objects)
public static java.lang.Object[][] $$(java.lang.Object[]... objects)
$(java.lang.Object...)public static void sleep(long millis)
Thread.sleep(long).public static void assumeTrue(boolean condition)
Assume.assumeTrue(boolean) directly available.public static void assumeFalse(boolean condition)
assumeTrue(boolean).public static void assumeNotNull(java.lang.Object... objects)
Assume.assumeNotNull(Object...) directly available.public static void assumeTrue(java.lang.String message,
boolean condition)
condition - If false an AssumptionViolatedException is
thrown by this method and the test case (should be) ignored (or
rather technically, flagged as a failure not passing a certain
assumption). Tests that are assumption-failures do not break
builds (again: typically).message - Message to be included in the exception's string.public static void assumeFalse(java.lang.String message,
boolean condition)
assumeTrue(String, boolean).public static void assumeNoException(java.lang.String msg,
java.lang.Throwable t)
t is null.public static void assumeNoException(java.lang.Throwable t)
Assume.assumeNoException(Throwable) directly available.public static double systemPropertyAsDouble(java.lang.String propertyName,
double defaultValue)
public static float systemPropertyAsFloat(java.lang.String propertyName,
float defaultValue)
public static int systemPropertyAsInt(java.lang.String propertyName,
int defaultValue)
public static float systemPropertyAsLong(java.lang.String propertyName,
int defaultValue)
public static boolean systemPropertyAsBoolean(java.lang.String propertyName,
boolean defaultValue)
true if the property exists an is set to any of the following strings
(case-insensitive): true, on, yes, enabled.
false is returned if the property exists and is set to any of the
following strings (case-insensitive):
false, off, no, disabled.
Copyright © 2011–2018 Carrot Search s.c.. All rights reserved.