Welcome to our community! Before you start writing testcases, you should make sure your configuration is correct, and take a look at How We Do Things. The best way to do both is to examine our example, which is an SWT-ized version of Scenario 2 from Satadip Dutta's article in the April 03 Java Developer's Journal:
Note that the following assumes that
You can run the example in 3 ways, which you should probably try to run in the following order:
Run the example "standalone," i.e. from your devbench without launching a runbench. This mode is probably not useful if you're developing a plugin, but for a "normal" application it's probably all you need. To do this:
In your devbench, open the JUnit view (from the mainmenu, Windows>Show View>Other>Java>JUnit).
Create a launch configuration: from the mainmenu, Run>Run>JUnit, New: give it a name, project=abbotforswt (or your plugin's name), test class=com.ibm.abbot.examples.CelsiusConverterTest (or your testcase's name), Apply.
Change to the Arguments tab. If running SWT, "VM arguments" must point to your SWT dll. Depending on your version of Eclipse, and how you have it installed, and your target platform, the appropriate string will be something like
-Djava.library.path=w:\eclipse\plugins\org.eclipse.swt.win32_2.1.2\os\win32\x86
Run: HANDS OFF MOUSE AND KEYBOARD! for the duration of the test. Also, keep your eyes on the screen, because this test runs fast, since no runbench needs to launch, just the SWT SUT (CelsiusConverter.java, the "Convert Celsius to Fahrenheit" dialog). Unfortunately you get no feedback when the test is done, so remember to first open the the JUnit view.
If you can't get this running, you've got problems. If you can run this, and you want only to test a standalone UI, you should be good to go. But if you want to test inside a workbench (i.e. to test plugins you are developing _for_ Eclipse), the next step is to run inside a launched instance.
You can also run from pde.junit, if you target an Eclipse or WebSphere Studio build. This uses more standard Eclipse tools and eliminates the need for separate launch and run steps. To do this, you must have the appropriate plugin (probably o.e.pde.junit) installed in your devbench. You have it if you see the option, from the mainmenu, to Run>JUnit Plug-in Test. Otherwise, install it from the o.e.jdt.junit site (yes, I know the names differ, and I don't know why)
http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/jdt-ui-home/plugins/org.eclipse.jdt.junit/index.html
(IIRC it comes with workbenches >= 3.0). To run the demo using pde.junit (if pointing to Eclipse or WSAD target):
In your devbench, open the JUnit view (from the mainmenu, Windows>Show View>Other>Java>JUnit).
from devbench mainmenu, Run>Run>JUnit Plug-in Test, New: give it a name and location, project=abbotforswt, test class=com.ibm.abbot.examples.CelsiusConverterTest.
Switch to the Arguments tab. If not default, specify appname=o.e.pde.junit.uitestapplication, and preferably "Clear test workspace data before launching". Specify the VM Arguments (which need not point to the SWT jar--that's required only for use standalone/non-launching) and Program Arguments that you usually use to launch a runbench for testing.
Switch to the "Plug-ins and Fragments" tab: ensure abbotforswt is one of the launched plugins, or just take the defaults.
Hit Run: HANDS OFF MOUSE AND KEYBOARD! for the duration of the test. Note that, on my 1 GHz, 1 GB PC, it takes ~15 sec for the runbench to launch. Then watch testcase drive the UI.
Note that, in some versions of pde.junit,
One can also manually run a JUnit TestRunner from a launched target build. Unfortunately I don't know how to do this from a launched Eclipse, only from a launched WebSphere Studio build, which is internally instrumented with a Test Collector. (As is, this is probably only useful to IBMers, but the tools are standard, so feel free to roll your own if they are not already available to you.) The TC provides UI allowing one to choose testsuites and -cases to run, then launches a Swing TestRunner. To run the demo this way:
From devbench mainmenu: Run>Run>Run-time Workbench, New: give it a name and location, and preferably "Clear workspace data before launching". Ensure abbotforswt is one of the launched plugins: see the "Plug-ins and Fragments" tab.
Hit Apply, Run. When the runbench comes up,
From runbench mainmenu: Test Collector>Test Collector.
Choose AbbotSWT Tests from the TC dialog's combo. (This extension is contributed by the abbotforswt plugin.)
Check the box under Test Suites, hit Run Tests. HANDS OFF MOUSE AND KEYBOARD! for the duration of the test. The Swing TestRunner and the SUT will popup. Watch the testcase drive the UI.
When the test is done the JUnit bar will be all one color (preferably green), and the JUnit status bar will say "Finished:" followed by the elapsed time (~30 sec, YMMV). Your UI will remain up, as will the TestRunner and TestCollector.
If you can do all of the above, you are ready to start writing testcases for your plugin (or project).
If you would like to help us develop or document, please send me an email!