Running Eclipse Plug-in tests on a non-ui-thread

How do I run an Eclipse JUnit plug-in test on a non-ui thread when running tests from the command line? In the Run Configuration dialog box, I can clear the Run on UI Thread checkbox, but how do I do this when running tests at the command line?

EDIT: This seems to be org.eclipse.pde.junit.runtime.nonuithreadtestapplication

what triggers the PDE when running tests on a non-UI thread, but when I try to use it, I get "parameter" -port "not found":

Loading logger configuration: c: \ work \ dev \ tooticki \ core \ ide \ eclipse \ plugins \ com.iar.ide.tests \ logging.properties
23: 42: 51,349 [main] INFO ew - Starting application: class com.iar.ew.Application
Exception in thread "WorkbenchTestable" java.lang.IllegalArgumentException: Error: parameter '-port' not specified
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.defaultInit (RemoteTestRunner.java:303)
    at org.eclipse.pde.internal.junit.runtime.RemotePluginTestRunner.init (RemotePluginTestRunner.java:83)
    at org.eclipse.pde.internal.junit.runtime.RemotePluginTestRunner.main (RemotePluginTestRunner.java:61)
    at org.eclipse.pde.internal.junit.runtime.NonUIThreadTestApplication.runTests (NonUIThreadTestApplication.java:23)
    at org.eclipse.ui.internal.testing.WorkbenchTestable $ 1.run (WorkbenchTestable.java:71)
    at java.lang.Thread.run (Thread.java:619)
+2


source to share


3 answers


When you say you run tests from the command line, do you mean by calling PDE ant targets?

The ant task for running PDE tests has two purposes: core-test and ui-test for headless and UI testing respectively. There is an article on the Eclipse Test Framework here with more details, but essentially you can just select the appropriate target and as long as your code under test doesn't need to have access to the UI, your tests will run under the main test target. You may also find this Eclipse Corner article on PDE and Ant helpful



If you call tests in a different way. You can still look at the PDE ant task source to understand how they set up the environment

+1


source


Create a new application class that extends from org.eclipse.pde.internal.junit.runtime.UITestApplication:

public class NonUIThreadTestApplication extends UITestApplication {
  public void runTests() {
    fTestableObject.testingStarting();
    try {
      EclipseTestRunner.run(Platform.getCommandLineArgs());
    } catch (IOException e) {
      e.printStackTrace();
    }
    fTestableObject.testingFinished();
  }
}

      

I think you should copy the EclipseTestRunner like from the org.eclipse.test plugin into your plugin due to dependency restrictions.

Add a new app to your plugin.xml:

<extension
         id="nonuithreadtestapplication"
         point="org.eclipse.core.runtime.applications">
  <application visible="false">
    <run class="com.my.test.NonUIThreadTestApplication" />
  </application>
</extension>

      



Add a new section to org.eclipse.test / library.xml:

<target name="nonui-thread-ui-test" description="Eclipse application used to launch UI plugin tests in a non-UI thread." depends="init">
  <antcall target="${launchTarget}">
    <param name="application" value="com.my.test.nonuithreadtestapplication" />
  </antcall>
</target>

      

After that, you can run your tests using nonui-thread-ui-test

target instead of ui-test

or core-test

.

Good luck!

+1


source


Apparently org.eclipse.pde.junit.runtime.nonuithreadtestapplication

a dedicated listener for test results is needed. How to do this is described in this article .

0


source







All Articles