Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "SWT/Devel/Gtk/JUnitTests"

< SWT‎ | Devel‎ | Gtk
m (Running jUnit tests across multiple versions of GTK)
m (Running jUnit tests across multiple versions of GTK)
Line 24: Line 24:
 
Running them one by one is tedious. A script is provided to run them in a batch.
 
Running them one by one is tedious. A script is provided to run them in a batch.
  
TODO - Link to script in repo.
+
The script's location is:
 +
 
 +
    ~/git/eclipse.platform.swt/tests/org.eclipse.swt.tests/gtk_version_tests.sh
 +
 
 +
Configuration (including pulling of external repo for gtk builds) and usage is documented inside the script itself.
 +
 
 +
As a side note, submission was in: [https://bugs.eclipse.org/bugs/show_bug.cgi?id=494540 this bugzilla ticket.]
  
 
An example output of the script looks as following:
 
An example output of the script looks as following:

Revision as of 02:40, 25 May 2016

Background

SWT comes with a set of JUnit test cases that test a wide cross section of widgets in the SWT codebase. Running these tests after writing a patch is useful to see if your patch breaks anything else in addition to your changes.

Location

The tests are located in the org.eclipse.swt.tests project, assuming you imported all the projects in the SWT git repository. If you have not done so, you can import the project from this path:

 <git location>/eclipse.platform.swt/tests/org.eclipse.swt.tests       # Where <git location> is the location of your gitroot.

Running Tests

The tests that concern most SWT developers will be the AllNonBrowserTests.java file. This contains the non-browser tests that will test a variety of widgets. To run it, open the file, and click the run button. Eclipse should automatically load the JUnit test runner and run the tests. Make sure you run the tests in Gtk3 and Gtk2, as that can make quite a difference depending on the patch you are testing.

NoDef/Initialization Errors

You may encounter the following error (or something similar) after upgrading your version of Eclipse or running the JUnit test suite for the first time:

 java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing

This is fixed by editing your build path for the org.eclipse.swt.tests project. To do, execute the following steps:

  • Right click the project in the Package Explorer and hover over "Build Path"
  • Select "Add Libraries" from the side menu
  • Select "JUnit" and click next
  • Select "JUnit 4" and click finish
  • Run the tests again, they should work

Running jUnit tests across multiple versions of GTK

Before submitting a patch, you generally want make sure that your code passes all jUnit tests on all major versions of gtk. Running them one by one is tedious. A script is provided to run them in a batch.

The script's location is:

   ~/git/eclipse.platform.swt/tests/org.eclipse.swt.tests/gtk_version_tests.sh

Configuration (including pulling of external repo for gtk builds) and usage is documented inside the script itself.

As a side note, submission was in: this bugzilla ticket.

An example output of the script looks as following:

Running swt jUnit tests. This may take a while.
Warnings redirected to gtk_test_error.log. Copy of output in gtk_test_out.log
 
------ Testing with gtk libraries from current system ------
SWT.getVersion(): 4622
org.eclipse.swt.internal.DPIUtil.getDeviceZoom(): 100
org.eclipse.swt.internal.gtk.version=3.20.3
    ~~ SUMMARY ~~
    3.20.3 GTK_TEST_RESULT : SOME TESTS FAIL: 2 / 3016
    1: test_setTopItemLorg_eclipse_swt_widgets_TreeItem(org.eclipse.swt.tests.junit.Test_org_eclipse_swt_widgets_Tree): expected: org.eclipse.swt.widgets.TreeItem<TreeItem {}> but was: org.eclipse.swt.widgets.TreeItem<TreeItem {}>
    2: test_getPrinterList(org.eclipse.swt.tests.junit.Test_org_eclipse_swt_printing_Printer): printer list contains items even though there are no printers
 
------ Testing with 3.20.4 ---------------
SWT.getVersion(): 4622
org.eclipse.swt.internal.DPIUtil.getDeviceZoom(): 100
org.eclipse.swt.internal.gtk.version=3.20.4
    ~~ SUMMARY ~~
    3.20.4 GTK_TEST_RESULT : SOME TESTS FAIL: 1 / 3016
    1: test_setTopItemLorg_eclipse_swt_widgets_TreeItem(org.eclipse.swt.tests.junit.Test_org_eclipse_swt_widgets_Tree): expected: org.eclipse.swt.widgets.TreeItem<TreeItem {}> but was: org.eclipse.swt.widgets.TreeItem<TreeItem {}>
 
------ Testing with 3.18.9 ---------------
SWT.getVersion(): 4622
org.eclipse.swt.internal.DPIUtil.getDeviceZoom(): 100
org.eclipse.swt.internal.gtk.version=3.18.9
    ~~ SUMMARY ~~
    3.18.9 GTK_TEST_RESULT : ALL TESTS PASS
 
------ Testing with 3.16.7 ---------------
SWT.getVersion(): 4622
org.eclipse.swt.internal.DPIUtil.getDeviceZoom(): 100
org.eclipse.swt.internal.gtk.version=3.16.7
    ~~ SUMMARY ~~
    3.16.7 GTK_TEST_RESULT : ALL TESTS PASS
 
------ Testing with 3.14.15 ---------------
SWT.getVersion(): 4622
org.eclipse.swt.internal.DPIUtil.getDeviceZoom(): 100
org.eclipse.swt.internal.gtk.version=3.14.15
    ~~ SUMMARY ~~
    3.14.15 GTK_TEST_RESULT : ALL TESTS PASS
 
------ Testing with Gtk 2.24 ------------------
SWT.getVersion(): 4622
org.eclipse.swt.internal.DPIUtil.getDeviceZoom(): 100
org.eclipse.swt.internal.gtk.version=2.24.30
1.2: style 0x800; expected: Rectangle {100, 200, 200, 200}, but was: Rectangle {100, 200, 196, 196}
2.2: style 0x10; expected: Rectangle {100, 200, 200, 200}, but was: Rectangle {100, 200, 194, 231}
5.2: style 0x20; expected: Rectangle {100, 200, 200, 200}, but was: Rectangle {100, 200, 200, 214}
    ~~ SUMMARY ~~
    2.24.30 GTK_TEST_RESULT : ALL TESTS PASS
 
 
 ~~SUMMARY OF SUMMARIES:
    3.20.3 GTK_TEST_RESULT : SOME TESTS FAIL: 2 / 3016
    3.20.4 GTK_TEST_RESULT : SOME TESTS FAIL: 1 / 3016
    3.18.9 GTK_TEST_RESULT : ALL TESTS PASS
    3.16.7 GTK_TEST_RESULT : ALL TESTS PASS
    3.14.15 GTK_TEST_RESULT : ALL TESTS PASS
    2.24.30 GTK_TEST_RESULT : ALL TESTS PASS
 
To see warnings that were thrown during tests, see: gtk_test_error.log

Back to the top