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.TestCaseConvenient 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 voidbuildWorkspace()Builds the workspace, waiting for build completion.protected voidcleanUpWorkspace()Deletes all resources in the workspace.protected org.eclipse.core.resources.IProjectgetProject(java.lang.String name)Shortcut togetWorkspaceRoot().getProject(name).protected org.eclipse.core.resources.IWorkspacegetWorkspace()Shortcut toResourcesPlugin.getWorkspace().protected org.eclipse.core.resources.IWorkspaceRootgetWorkspaceRoot()Shortcut togetWorkspace().getRoot().protected voidsetAutoBuilding(boolean value)Sets the property "Build Automatically" for the workspace.protected voidsetUp()Turns auto-build off, cleans up the workspace.protected org.eclipse.core.resources.IProjectsetUpProject(java.lang.String name)Creates a new project in the workspace by copying its content from the OSGi-bundle of this test case.protected voidtearDown()Cleans up the workspace.protected voidwaitForBuildCompletion()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.ExceptionTurns auto-build off, cleans up the workspace.- Overrides:
setUpin classjunit.framework.TestCase- Throws:
java.lang.Exception
-
tearDown
protected void tearDown() throws java.lang.ExceptionCleans up the workspace.- Overrides:
tearDownin 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.IOExceptionCreates 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.CoreExceptionjava.io.IOException
-
setAutoBuilding
protected final void setAutoBuilding(boolean value) throws org.eclipse.core.runtime.CoreExceptionSets 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
-
-