Reputation: 2389
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 :
ClientBundle
that provide the CSS file used for tests.gwtSetUp()
, call the `ensureInjected() method to add the CSS file before my tests get calledcode:
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;
}
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.
Upvotes: 0
Views: 224
Reputation: 64541
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.xml
file) dedicated for your tests (make it <inherits>
your module-under-test and have your GWTTestCase
's getModuleName
return 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 a public
subfolder next to the test-specific gwt.xml
file).
See https://developers.google.com/web-toolkit/doc/latest/DevGuideOrganizingProjects#DevGuideAutomaticResourceInclusion
Alternatively, using CssResource
as you did, you might want to call StyleInjector.flush()
just after your call to ensureInjected()
.
Upvotes: 2