public class TestUtils
extends java.lang.Object
| Constructor and Description |
|---|
TestUtils() |
| Modifier and Type | Method and Description |
|---|---|
static java.io.File |
createTempDirDeletedOnExit() |
static void |
deleteFile(java.io.File dir) |
static void |
eventually(java.lang.Runnable runnable)
Asserts that a runnable will eventually not throw an assertion exception.
|
static void |
eventually(java.lang.Runnable runnable,
java.time.Duration duration)
Asserts that a runnable will eventually not throw
AssertionError before
timeoutMs milliseconds have ellapsed |
static java.lang.String |
getDiff(java.lang.String[] before,
java.lang.String[] after) |
static java.lang.String |
getDiff(java.lang.String[] before,
java.lang.String[] after,
int windowSize) |
static java.lang.String |
getDiff(java.lang.String before,
java.lang.String after) |
static java.lang.String |
getDiff(java.lang.String before,
java.lang.String after,
int windowSize) |
static java.lang.String |
getKotlinVersionForTests()
Returns Kotlin version that is used in new project templates and integration tests.
|
static java.lang.String |
getLatestAndroidPlatform() |
static java.io.File |
getNdk()
Returns the path to checked-in NDK.
|
static java.io.File |
getPlatformFile(java.lang.String path)
Returns a file at
path relative to the root for getLatestAndroidPlatform(). |
static java.lang.String |
getRelativeSdk()
Returns the SDK directory relative to the workspace.
|
static java.nio.file.Path |
getRemoteSdk()
Returns the remote SDK directory.
|
static java.io.File |
getRoot(java.lang.String... names)
Deprecated.
Use
getWorkspaceRoot() or getWorkspaceFile(String) instead. |
static java.io.File |
getSdk()
Returns the SDK directory.
|
static java.io.File |
getTestOutputDir() |
static java.io.File |
getWorkspaceFile(java.lang.String path)
Given a full path to a file from the base of the current workspace, return the file.
|
static java.io.File |
getWorkspaceRoot()
Returns the root of the entire Android Studio codebase.
|
static void |
launchProcess(java.lang.Class toRun,
java.lang.String... args)
Launches a new process to execute the class
toRun main() method and blocks until the
process exits. |
static boolean |
runningFromBazel()
Checks if tests were started by Bazel.
|
static void |
waitForFileSystemTick()
Sleeps the current thread for enough time to ensure that the local file system had enough
time to notice a "tick".
|
static void |
waitForFileSystemTick(long currentTimestamp)
Sleeps the current thread for enough time to ensure that the local file system had enough
time to notice a "tick".
|
@NonNull public static java.lang.String getKotlinVersionForTests()
This version is determined based on the checked-in kotlin-plugin prebuilt, and should be in sync with the version in:
@Deprecated @NonNull public static java.io.File getRoot(java.lang.String... names)
getWorkspaceRoot() or getWorkspaceFile(String) instead.public static void deleteFile(java.io.File dir)
public static java.io.File createTempDirDeletedOnExit()
@NonNull public static java.io.File getWorkspaceRoot()
From this path, you should be able to access any file in the workspace via its full path, e.g.
new File(TestUtils.getWorkspaceRoot(), "tools/adt/idea/android/testSrc"); new File(TestUtils.getWorkspaceRoot(), "prebuilts/studio/jdk");
If this method is called by code run via IntelliJ / Gradle, it will simply walk its ancestor tree looking for the WORKSPACE file at its root; if called from Bazel, it will simply return the runfiles directory (which should be a mirror of the WORKSPACE root except only populated with explicitly declared dependencies).
Instead of calling this directly, prefer calling getWorkspaceFile(String) as it
is more resilient to cross-platform testing.
java.lang.IllegalStateException - if the current directory of the test is not a subdirectory of
the workspace directory when this method is called. This shouldn't happen if the test is
run by Bazel or run by IntelliJ with default configuration settings (where the working
directory is initialized to the module root).@NonNull
public static java.io.File getWorkspaceFile(@NonNull
java.lang.String path)
java.lang.IllegalArgumentException - if the path results in a file that's not found.@NonNull public static java.io.File getTestOutputDir()
@NonNull public static java.io.File getPlatformFile(java.lang.String path)
path relative to the root for getLatestAndroidPlatform().java.lang.IllegalStateException - if the current OS is not supported.java.lang.IllegalArgumentException - if the path results in a file not found.public static boolean runningFromBazel()
@NonNull public static java.lang.String getRelativeSdk()
java.lang.IllegalStateException - if the current OS is not supported.java.lang.IllegalArgumentException - if the path results in a file not found.@NonNull public static java.io.File getSdk()
java.lang.IllegalStateException - if the current OS is not supported.java.lang.IllegalArgumentException - if the path results in a file not found.@NonNull public static java.io.File getNdk()
getSdk()@NonNull public static java.nio.file.Path getRemoteSdk()
java.lang.IllegalArgumentException - if the path results in a file not found.@NonNull public static java.lang.String getLatestAndroidPlatform()
public static void waitForFileSystemTick()
throws java.lang.InterruptedException,
java.io.IOException
java.lang.InterruptedException - waiting interruptedjava.io.IOException - issues creating a temporary filepublic static void waitForFileSystemTick(long currentTimestamp)
throws java.lang.InterruptedException,
java.io.IOException
currentTimestamp - last timestamp read from diskjava.lang.InterruptedException - waiting interruptedjava.io.IOException - issues creating a temporary file@NonNull
public static java.lang.String getDiff(@NonNull
java.lang.String before,
@NonNull
java.lang.String after)
@NonNull
public static java.lang.String getDiff(@NonNull
java.lang.String before,
@NonNull
java.lang.String after,
int windowSize)
@NonNull
public static java.lang.String getDiff(@NonNull
java.lang.String[] before,
@NonNull
java.lang.String[] after)
public static java.lang.String getDiff(@NonNull
java.lang.String[] before,
@NonNull
java.lang.String[] after,
int windowSize)
public static void eventually(@NonNull
java.lang.Runnable runnable)
eventually(Runnable, Duration), but using a default timeoutrunnable - a description of the failure, if the condition never becomes truepublic static void eventually(@NonNull
java.lang.Runnable runnable,
java.time.Duration duration)
AssertionError before
timeoutMs milliseconds have ellapsedrunnable - a description of the failure, if the condition never becomes trueduration - the timeout for the predicate to become truepublic static void launchProcess(@NonNull
java.lang.Class toRun,
java.lang.String... args)
toRun main() method and blocks until the
process exits.toRun - the class whose main() method will be executed in a new process.args - the arguments for the class toRun main() methodjava.lang.RuntimeException - if any (checked or runtime) exception occurs or the process returns
an exit value other than 0