public class RandomizedTest
extends org.junit.Assert
Listeners
,
RandomizedContext
Modifier and Type | Field and Description |
---|---|
protected static Charset |
ISO8859_1 |
static String |
SYSPROP_MULTIPLIER
The global multiplier property (Double).
|
protected static Charset |
US_ASCII |
protected static Charset |
UTF16 |
protected static Charset |
UTF32 |
protected static Charset |
UTF8 |
Constructor and Description |
---|
RandomizedTest() |
Modifier and Type | Method and Description |
---|---|
static Object[] |
$(Object... objects)
This is an absolutely hacky utility to take a vararg as input and return the array
of arguments as output.
|
static Object[][] |
$$(Object[]... objects) |
static void |
assumeFalse(boolean condition)
Reverse of
assumeTrue(boolean) . |
static void |
assumeFalse(String message,
boolean condition)
Reverse of
assumeTrue(String, boolean) . |
static void |
assumeNoException(String msg,
Throwable t)
Assume
t is null . |
static void |
assumeNoException(Throwable t)
Making
Assume.assumeNoException(Throwable) directly available. |
static void |
assumeNotNull(Object... objects)
Making
Assume.assumeNotNull(Object...) directly available. |
static void |
assumeTrue(boolean condition)
Making
Assume.assumeTrue(boolean) directly available. |
static void |
assumeTrue(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 <T extends Closeable> |
closeAfterSuite(T resource)
Registers a
Closeable resource that should be closed after the suite
completes. |
<T extends 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 Random |
getRandom()
Shortcut for
RandomizedContext.getRandom() . |
static File |
globalTempDir()
Global temporary directory created for the duration of this class's lifespan.
|
static boolean |
isNightly()
Returns true if we're running nightly tests.
|
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 ServerSocket |
newServerSocket(LifecycleScope scope)
Assign a temporary server socket.
|
File |
newTempDir()
Creates a new temporary directory for the
LifecycleScope.TEST duration. |
static File |
newTempDir(LifecycleScope scope)
Creates a temporary directory, deleted after the given lifecycle phase.
|
File |
newTempFile()
Creates a new temporary file for the
LifecycleScope.TEST duration. |
static File |
newTempFile(LifecycleScope scope)
Creates a new temporary file deleted after the given lifecycle phase completes.
|
static String |
randomAsciiOfLength(int codeUnits) |
static String |
randomAsciiOfLengthBetween(int minCodeUnits,
int maxCodeUnits) |
static boolean |
randomBoolean() |
static byte |
randomByte() |
static double |
randomDouble() |
static float |
randomFloat() |
static <T> T |
randomFrom(List<T> list)
Pick a random object from the given list.
|
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)
A random integer from 0..max (inclusive).
|
static int |
randomIntBetween(int min,
int max)
A random integer from
min to max (inclusive). |
static Locale |
randomLocale()
Return a random Locale from the available locales on the system.
|
static long |
randomLong() |
static String |
randomRealisticUnicodeOfCodepointLength(int codePoints) |
static String |
randomRealisticUnicodeOfCodepointLengthBetween(int minCodePoints,
int maxCodePoints) |
static String |
randomRealisticUnicodeOfLength(int codeUnits) |
static String |
randomRealisticUnicodeOfLengthBetween(int minCodeUnits,
int maxCodeUnits) |
static short |
randomShort() |
static TimeZone |
randomTimeZone()
Return a random TimeZone from the available timezones on the system.
|
static String |
randomUnicodeOfCodepointLength(int codePoints) |
static String |
randomUnicodeOfCodepointLengthBetween(int minCodePoints,
int maxCodePoints) |
static String |
randomUnicodeOfLength(int codeUnits) |
static String |
randomUnicodeOfLengthBetween(int minCodeUnits,
int maxCodeUnits) |
static boolean |
rarely()
Rarely returns
true in about 10% of all calls (regardless of the
isNightly() mode). |
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(String propertyName,
boolean defaultValue)
Get a system property and convert it to a boolean, if defined.
|
static double |
systemPropertyAsDouble(String propertyName,
double defaultValue)
Get a system property and convert it to a double, if defined.
|
static float |
systemPropertyAsFloat(String propertyName,
float defaultValue)
Get a system property and convert it to a float, if defined.
|
static int |
systemPropertyAsInt(String propertyName,
int defaultValue)
Get a system property and convert it to an int, if defined.
|
static float |
systemPropertyAsLong(String propertyName,
int defaultValue)
Get a system property and convert it to a long, if defined.
|
assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotEquals, assertNotEquals, assertNotEquals, assertNotEquals, assertNotEquals, assertNotEquals, assertNotEquals, assertNotEquals, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertThat, assertThat, assertTrue, assertTrue, fail, fail
public static final String SYSPROP_MULTIPLIER
multiplier()
,
Constant Field Valuesprotected static final Charset UTF8
protected static final Charset UTF16
protected static final Charset ISO8859_1
protected static final Charset US_ASCII
protected static final Charset UTF32
public static RandomizedContext getContext()
RandomizedContext.current()
.public static boolean isNightly()
Nightly
public static 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 int randomInt(int 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 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(List<T> list)
public static double multiplier()
The default multiplier value is 1.
SYSPROP_MULTIPLIER
,
DEFAULT_MULTIPLIER
public 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 File globalTempDir()
public File newTempDir()
LifecycleScope.TEST
duration.globalTempDir()
public static File newTempDir(LifecycleScope scope)
public <T extends Closeable> T closeAfterTest(T resource)
Closeable
resource that should be closed after the test
completes.resource
(for call chaining).public static <T extends Closeable> T closeAfterSuite(T resource)
Closeable
resource that should be closed after the suite
completes.resource
(for call chaining).public File newTempFile()
LifecycleScope.TEST
duration.public static File newTempFile(LifecycleScope scope)
public static ServerSocket newServerSocket(LifecycleScope scope) throws IOException
scope
- The lifecycle scope to close the socket after. If the socket is
closed earlier, nothing happens (silently dropped).IOException
public static 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 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.
public static String randomAsciiOfLengthBetween(int minCodeUnits, int maxCodeUnits)
public static String randomAsciiOfLength(int codeUnits)
public static String randomUnicodeOfLengthBetween(int minCodeUnits, int maxCodeUnits)
public static String randomUnicodeOfLength(int codeUnits)
public static String randomUnicodeOfCodepointLengthBetween(int minCodePoints, int maxCodePoints)
public static String randomUnicodeOfCodepointLength(int codePoints)
public static String randomRealisticUnicodeOfLengthBetween(int minCodeUnits, int maxCodeUnits)
public static String randomRealisticUnicodeOfLength(int codeUnits)
public static String randomRealisticUnicodeOfCodepointLengthBetween(int minCodePoints, int maxCodePoints)
public static String randomRealisticUnicodeOfCodepointLength(int codePoints)
public static Object[] $(Object... objects)
public static Object[][] $$(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(Object... objects)
Assume.assumeNotNull(Object...)
directly available.public static void assumeTrue(String message, boolean condition)
condition
- If false
an InternalAssumptionViolatedException
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(String message, boolean condition)
assumeTrue(String, boolean)
.public static void assumeNoException(Throwable t)
Assume.assumeNoException(Throwable)
directly available.public static double systemPropertyAsDouble(String propertyName, double defaultValue)
public static float systemPropertyAsFloat(String propertyName, float defaultValue)
public static int systemPropertyAsInt(String propertyName, int defaultValue)
public static float systemPropertyAsLong(String propertyName, int defaultValue)
public static boolean systemPropertyAsBoolean(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–2015 Carrot Search s.c.. All rights reserved.