When writing plugin tests, a common task is testing various kinds of highlighting (inspections, annotators, parser error highlighting, etc.). The IntelliJ Platform provides a dedicated utility and markup format for this task.
To test the highlighting for the file currently loaded into the in-memory editor, you invoke the
checkHighlighting() method. The parameters to the method specify which severities should be taken into account when comparing the results with the expected results: errors are always taken into account, whereas warnings, weak warnings, and infos are optional. To ignore verifying additional highlighting, set parameter
true. Alternatively, you can use the
testHighlighting() method, which loads a testdata file into the in-memory editor and highlights it as a single operation.
If you need to test inspections (rather than generic highlighting provided by a highlighting lexer or annotator), you need to enable inspections that you're testing. This is done by calling
CodeInsightTestFixture.enableInspections() in the setup method of your test or directly in a test method, before the call to
The expected results of the highlighting are specified directly in the source file. The platform supports an extensive XML-like markup language for this. In its simplest form, the markup looks like this:
Or, as a more specific example:
The tag name specifies the severity of the expected highlighting. The following severities are supported:
<inject>for an injected fragment
<symbolName>for a marker that highlights an identifier according to its type
any custom severity can be referenced by its name
The tag can also have the following optional attributes:
descrexpected (hardcoded) message associated with the highlighter (if not specified, any text will match; if the message contains a quotation mark, it can be escaped by putting two backslash characters before it)
bundleMsgexpected message from message bundle in format
[bundleName#] bundleKey [|argument]...
tooltipexpected tooltip message
TextAttributesKeyreferenced by its
effectColorexpected colors for the highlighting
effectTypeexpected effect type for the highlighting (see
fontTypeexpected font style for the highlighting (
3- bold italic)