Configuring and Running a CoView JUnit Plug-in Test

The following instructions guide you through configuring CoView to run JUnit tests against other Eclipse Plug-ins.

Configuring the Plug-in


To run a plug-in test in CoView, you must first add two dependencies to your plug-in’s manifest.

The first dependency is the org.junit Eclipse library plug-in, which allows your plug-in to access the JUnit library.  The second dependency is the CoViewInstPlugin plug-in, which allows CoView to instrument your plug-in’s code while it is running in an Eclipse runtime.

  • 1. Open your plug-in’s plugin.xml file (or MANIFEST.MF file if plugin.xml does not exist).
  • 2. Click on the Dependencies tab.
  • 3. In the Required Plug-ins tab, click the Add button, type “org.junit” and click OK.
  • 4. In the Required Plug-ins tab, click the Add button, type “CoViewInstPlugin” and click OK.

Storing Test Files in the Plug-in Under Test

There are two ways to store JUnit tests for a plug-in project.

The first requires adding the JUnit tests directly to the plug-in being tested.  You can either put the tests in the same package as the classes under test or create a new source folder for them.  If you use a source folder, create a parallel package structure to the classes under test for package level access.

Storing Test Files in a Separate Plug-in


One disadvantage of having the tests exist with the classes under test is that it clutters your plug-in with dependencies that are not required for running it.  You can decouple your tests and your classes under test by creating another plug-in for the tests, which we will call the ExternalPluginTest project. 

  • 1. Run an Eclipse workspace that contains the plug-in you would like to test.
  • 2. Click on File menu.
  • 3. Select New, then Project…
  • 4. In the New Project dialog, click on “Plug-in Project” and click the Next button.
  • 5. In the Plug-in Project page, name the plug-in, which this example will call “ExternalPluginTest”, and click Next.
  • 6. In the Plug-in Content page, select the defaults and click Next.
  • 7. In the Templates page, select the defaults and click Finish.

Now that you have created the ExternalPluginTest, you must add this dependency to the plug-in you're testing.  You also must add the two dependencies for org.junit and CoViewInstPlugin to this new plug-in.  Keep in mind that any Eclipse libraries needed for your JUnit tests must be added to the dependencies list as well.

  • 1. Open your plug-in’s MANIFEST.MF file.
  • 2. Click on the Dependencies tab.
  • 3. In the Required Plug-ins tab, click the Add button, type “org.junit” and click OK.
  • 4. Click the Add button again, type “CoViewInstPlugin” and click OK.
  • 5. Click the Add button again, type the name of your plug-in under test and click OK.

Finally, you must export any packages in the plug-in to be tested so that the external test plug-in can access the classes under test.

  • 1. Open your plug-in’s plugin.xml file (or MANIFEST.MF file if plugin.xml does not exist).
  • 2. Click on the Runtime tab.
  • 3. In the Exported Packages section, click the Add button and add the package to be exported and click OK.
  • 4. Repeat for all packages that contain classes under test.

Running a Plug-in Test

In the Package Explorer, right click on a test file, select Run As, and select CoView JUnit Plug-in Test.  If your tests are contained in the plug-in you are testing, this will launch an Eclipse runtime workspace with your plug-in running inside of it.  If you store your tests in a separate plug-in, this will launch an Eclipse runtime with both the plug-in under test and the plug-in containing the tests.

Once the Eclipse runtime workspace is launched, the JUnit tests specified will execute and the runtime will exit.  The CoView Test Manager will show the results of the test run.