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
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()
andtearDown()
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.
-
-
Constructor Summary
Constructors Constructor Description WorkspaceTestCase()
No-arg constructor to enable serialization.WorkspaceTestCase(java.lang.String name)
Constructs a test case with the given name.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
buildWorkspace()
Builds the workspace, waiting for build completion.protected void
cleanUpWorkspace()
Deletes all resources in the workspace.protected org.eclipse.core.resources.IProject
getProject(java.lang.String name)
Shortcut togetWorkspaceRoot().getProject(name)
.protected org.eclipse.core.resources.IWorkspace
getWorkspace()
Shortcut toResourcesPlugin.getWorkspace()
.protected org.eclipse.core.resources.IWorkspaceRoot
getWorkspaceRoot()
Shortcut togetWorkspace().getRoot()
.protected void
setAutoBuilding(boolean value)
Sets the property "Build Automatically" for the workspace.protected void
setUp()
Turns auto-build off, cleans up the workspace.protected org.eclipse.core.resources.IProject
setUpProject(java.lang.String name)
Creates a new project in the workspace by copying its content from the OSGi-bundle of this test case.protected void
tearDown()
Cleans up the workspace.protected void
waitForBuildCompletion()
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 Detail
-
WorkspaceTestCase
public WorkspaceTestCase()
No-arg constructor to enable serialization. This method is not intended to be used by mere mortals without calling setName().
-
WorkspaceTestCase
public WorkspaceTestCase(java.lang.String name)
Constructs a test case with the given name.
-
-
Method Detail
-
setUp
protected void setUp() throws java.lang.Exception
Turns auto-build off, cleans up the workspace.- Overrides:
setUp
in classjunit.framework.TestCase
- Throws:
java.lang.Exception
-
tearDown
protected void tearDown() throws java.lang.Exception
Cleans up the workspace.- Overrides:
tearDown
in classjunit.framework.TestCase
- Throws:
java.lang.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
protected final org.eclipse.core.resources.IProject getProject(java.lang.String name)
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(java.lang.String name) throws org.eclipse.core.runtime.CoreException, java.io.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
java.io.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.CoreException
Builds 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.CoreException
Deletes all resources in the workspace.- Throws:
org.eclipse.core.runtime.CoreException
-
-