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

    Constructors
    Constructor
    Description
    No-arg constructor to enable serialization.
    Constructs a test case with the given name.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected 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
    Shortcut to getWorkspaceRoot().getProject(name).
    protected final org.eclipse.core.resources.IWorkspace
    Shortcut to ResourcesPlugin.getWorkspace().
    protected final org.eclipse.core.resources.IWorkspaceRoot
    Shortcut to getWorkspace().getRoot().
    protected final void
    Resumes execution of jobs.
    protected final void
    setAutoBuilding(boolean value)
    Sets the property "Build Automatically" for the workspace.
    protected void
    Turns auto-build off, cleans up the workspace.
    protected final org.eclipse.core.resources.IProject
    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
    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

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • 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

      public WorkspaceTestCase(String name)
      Constructs a test case with the given name.
  • Method Details

    • setUp

      protected void setUp() throws Exception
      Turns auto-build off, cleans up the workspace.
      Overrides:
      setUp in class junit.framework.TestCase
      Throws:
      Exception
    • tearDown

      protected void tearDown() throws Exception
      Cleans up the workspace.
      Overrides:
      tearDown in class junit.framework.TestCase
      Throws:
      Exception
    • getWorkspace

      protected final org.eclipse.core.resources.IWorkspace getWorkspace()
      Shortcut to ResourcesPlugin.getWorkspace().
    • getWorkspaceRoot

      protected final org.eclipse.core.resources.IWorkspaceRoot getWorkspaceRoot()
      Shortcut to getWorkspace().getRoot().
    • getProject

      protected final org.eclipse.core.resources.IProject getProject(String name)
      Shortcut to getWorkspaceRoot().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.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
    • 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: