Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[platform-swt-dev] JUnit testing correct exceptions are thrown

I'm working on improving the JUnit tests for 
org.eclipse.swt.graphics.Image/ImageData, specifically testing exceptions. 
I've added a method SwtTestCase.assertEquals(String, int, Throwable) that 
checks if an API has thrown the expected exception. This is based on the 
SWT error code/message and not just the exception type. Anyone working on 
SWT JUnit tests should consider using this to verify the correct 
exceptions are thrown, as spec'd in the doc.
An example:
        try {
                image = new Image(display, -1, 10);
                image.dispose();
                fail("No exception thrown for width <= 0");
        } catch (IllegalArgumentException e) {
                assertEquals("Incorrect exception thrown for width <= 0", 
SWT.ERROR_INVALID_ARGUMENT, e);
        }

Knut


Back to the top