[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
|
[News.eclipse.test-and-performance] how to test effects of plugin code that uses Display.asyncExec ??
|
I see that all code inside testXXX methods defined in TestCases run in
the PDE junit runner, will be executed in the SWT Display thread.
this is generally OK, but if the plugin under test makes use of
Display.asyncExec then how can any testing be done ?
I'm quite familiar with writing plain-java multithreaded junit test
where essentially the thread running testXXX spawns other threads and
then waits for results.
But in the case of eclipse PDE junit, any Runnable that gets asyncExec'd
within a testXXX method, will never be executed before the testXXX
method terminates !
In fact the Runnable will be a queue element placed after the other
runnable whose execution stack contains testXXX.
TIA,
Edo
PS - please don't reply suggesting to use syncExec :-)
I'd done it where possible, not elsewhere ...
I'd even be happy even if the various asyncExec runnables posted
while PDE junit executed testXXX01
where effectively dequeued and executed *before* another
testXXX02 method
So, even if that's not good junit practice, I'd write two test method
one testing the consequence of the previous.
Example: IN a plugin project
//class under test
public class GlobalVar {
private static Object value;
public static Object getValue() {
return value;
}
public static void setValue(Object value) {
GlobalVar.value = value;
}
}
//tetscase to be run with PDE junit
public class AsynchTest extends TestCase {
private Display display;
protected void setUp() throws Exception {
display = PlatformUI.getWorkbench().getDisplay();
}
public void testCurrentThreadIsDisplay() {
assertSame(Thread.currentThread(), display.getThread());
assertNull(GlobalVar.getValue());
display.asyncExec(new Runnable() {
public void run() {
GlobalVar.setValue("bar");
}
});
//how can I test the value of GlobalVar
}
public void testAfterTheFirst() {
//I'd be happy enough even if I could test the effects
// of the previous test method here ...
}
}