I have some simple GWT client code that I would like to test using GWTTestCase and GWTTestSuite.
However, those tests require the use of some CSS stylesheet (only needed for the tests).
My first attempt was :
- Define a
ClientBundlethat provide the CSS file used for tests. - in my
gwtSetUp(), call the `ensureInjected() method to add the CSS file before my tests get called - Test if the CSS style was applied to a particular element in the DOM, for example
code:
assertEquals("blue", element.getStyle().getBorderColor());
I got no errors, but this not seems to work.
Looking throught the logs of the Console (during the Junit test) I found this :
Initializing ResourceGenerator
Finding operable CssResource subtypes
Computing CSS class replacements
Preparing method css
Finding resources
Parsing CSS stylesheet file:/D:/Workspace/libraries/gwt-text/gwt-text/src/test/java/com/t/i/client/CSSDecorationTest.css
Scanning CSS for requirements
Creating fields
Creating assignment for css()
Creating image sprite classes
Replacing property-based @if blocks
Replacing CSS class names
Performing substitution in node border-color : ….. ;
My css file simple contains :
.d {
border-color: blue;
}
EDIT
Please see this link : https://stackoverflow.com/a/10575244/921244
This was the wrong approach as getStyle do not provide the CSS computed style. Too bad.
If you don’t need to do anything special with your CSS (i.e. it’s a simple CSS, not a
CssResource), then you could simply create a GWT module (gwt.xmlfile) dedicated for your tests (make it<inherits>your module-under-test and have yourGWTTestCase‘sgetModuleNamereturn the name of the test-specific module instead of the module-under-test) in which you’d add a<stylesheet src="…" />to include your stylesheet (simplest way if the stylesheet is only to be used for tests, put it in apublicsubfolder next to the test-specificgwt.xmlfile).See https://developers.google.com/web-toolkit/doc/latest/DevGuideOrganizingProjects#DevGuideAutomaticResourceInclusion
Alternatively, using
CssResourceas you did, you might want to callStyleInjector.flush()just after your call toensureInjected().