Package org.eclipse.handly.junit
Class WorkspaceTestCase
java.lang.Object
junit.framework.Assert
junit.framework.TestCase
org.eclipse.handly.junit.WorkspaceTestCase
- All Implemented Interfaces:
junit.framework.Test
- Direct Known Subclasses:
NoJobsWorkspaceTestCase
public abstract class WorkspaceTestCase
extends junit.framework.TestCase
Convenient base class for test cases that operate on the Eclipse workspace.
Provides a number of useful methods, such as setUpProject(String)
.
Also, in its setUp()
and tearDown()
methods,
this class enforces some common rules for workspace tests:
- each test starts running in a clean workspace with auto-build turned off;
- each test is responsible for setting up the necessary workspace state;
- after running each test, the workspace is cleaned up.
Note that since version 1.7, there is also NoJobsWorkspaceTestCase
that additionally ensures that no jobs will execute while a test is running,
which helps avoid intermittent test failures due to unpredictable nature of
resource change notifications when multiple threads access the workspace
concurrently.
-
Constructor Summary
ConstructorDescriptionNo-arg constructor to enable serialization.WorkspaceTestCase
(String name) Constructs a test case with the given name. -
Method Summary
Modifier and TypeMethodDescriptionprotected final void
Builds the workspace, waiting for build completion.protected final void
Deletes all resources in the workspace.protected final org.eclipse.core.resources.IProject
getProject
(String name) Shortcut togetWorkspaceRoot().getProject(name)
.protected final org.eclipse.core.resources.IWorkspace
Shortcut toResourcesPlugin.getWorkspace()
.protected final org.eclipse.core.resources.IWorkspaceRoot
Shortcut togetWorkspace().getRoot()
.protected final void
Resumes execution of jobs.protected final void
setAutoBuilding
(boolean value) Sets the property "Build Automatically" for the workspace.protected void
setUp()
Turns auto-build off, cleans up the workspace.protected final org.eclipse.core.resources.IProject
setUpProject
(String name) Creates a new project in the workspace by copying its content from the OSGi-bundle of this test case.protected final void
Suspends execution of all jobs.protected void
tearDown()
Cleans up the workspace.protected final void
Waits for build completion.Methods inherited from class junit.framework.TestCase
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, countTestCases, createResult, fail, fail, failNotEquals, failNotSame, failSame, format, getName, run, run, runBare, runTest, setName, toString
-
Constructor Details
-
WorkspaceTestCase
public WorkspaceTestCase()No-arg constructor to enable serialization. This method is not intended to be used by mere mortals without calling setName(). -
WorkspaceTestCase
Constructs a test case with the given name.
-
-
Method Details
-
setUp
Turns auto-build off, cleans up the workspace.- Overrides:
setUp
in classjunit.framework.TestCase
- Throws:
Exception
-
tearDown
Cleans up the workspace.- Overrides:
tearDown
in classjunit.framework.TestCase
- Throws:
Exception
-
getWorkspace
protected final org.eclipse.core.resources.IWorkspace getWorkspace()Shortcut toResourcesPlugin.getWorkspace()
. -
getWorkspaceRoot
protected final org.eclipse.core.resources.IWorkspaceRoot getWorkspaceRoot()Shortcut togetWorkspace().getRoot()
. -
getProject
Shortcut togetWorkspaceRoot().getProject(name)
.- Parameters:
name
- the name of the project- Returns:
- the requested project (never
null
)
-
setUpProject
protected final org.eclipse.core.resources.IProject setUpProject(String name) throws org.eclipse.core.runtime.CoreException, IOException Creates a new project in the workspace by copying its content from the OSGi-bundle of this test case. The content needs to reside in the folder/workspace/
<project-name> inside the bundle.- Parameters:
name
- the name of the project- Returns:
- the created and opened project (never
null
) - Throws:
org.eclipse.core.runtime.CoreException
IOException
-
setAutoBuilding
protected final void setAutoBuilding(boolean value) throws org.eclipse.core.runtime.CoreException Sets the property "Build Automatically" for the workspace.- Parameters:
value
- boolean- Throws:
org.eclipse.core.runtime.CoreException
-
buildWorkspace
protected final void buildWorkspace() throws org.eclipse.core.runtime.CoreExceptionBuilds the workspace, waiting for build completion.- Throws:
org.eclipse.core.runtime.CoreException
-
waitForBuildCompletion
protected final void waitForBuildCompletion()Waits for build completion. -
cleanUpWorkspace
protected final void cleanUpWorkspace() throws org.eclipse.core.runtime.CoreExceptionDeletes all resources in the workspace.- Throws:
org.eclipse.core.runtime.CoreException
-
suspendJobs
protected final void suspendJobs()Suspends execution of all jobs.- Since:
- 1.7
- See Also:
-
resumeJobs
protected final void resumeJobs()Resumes execution of jobs.- Since:
- 1.7
- See Also:
-