Skip to content

Commit

Permalink
eclipse/xtext-core#253 Document testing API.
Browse files Browse the repository at this point in the history
- Add documentation about testing custom generators using the
CompilationTestHelper utility class.
- Add documentation about automated UI testing using the abstract base
classes in the org.eclipse.xtext.ui.testing package.

Signed-off-by: Tamas Miklossy <miklossy@itemis.de>
  • Loading branch information
miklossy committed Apr 6, 2020
1 parent 780ce5e commit 5470f7d
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
34 changes: 33 additions & 1 deletion xtext-website/documentation/103_domainmodelnextsteps.md
Expand Up @@ -339,7 +339,39 @@ This tutorial is about testing the parser, the linker and the validator for the
}
```

3. After saving the Xtend file, it is time to run the test. Select *Run As &rarr; JUnit Test* from the editor's context menu.
3. The [CompilationTestHelper]({{site.src.xtext_extras}}/org.eclipse.xtext.xbase.testing/src/org/eclipse/xtext/xbase/testing/CompilationTestHelper.java) utility class comes in handy while unit testing the custom generator implementations:

```xtend
@Inject extension CompilationTestHelper

@Test def test() {
'''
datatype String
package my.company.blog {
entity Blog {
title: String
}
}
'''.assertCompilesTo('''
package my.company.blog;

public class Blog {
private String title;
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
}
''')
}
```
4. After saving the Xtend file, it is time to run the tests. Select *Run As &rarr; JUnit Test* from the editor's context menu.
These tests serve only as a starting point and can be extended to cover the different features of the language. As a small exercise, you could implement e.g. test cases for the `checkFeatureNameIsUnique` validation rule. You can find more examples in the example projects shipped with the Xtext Framework. Simply go to *File &rarr; New &rarr; Example &rarr; Xtext Examples*.
Expand Down
16 changes: 16 additions & 0 deletions xtext-website/documentation/310_eclipse_support.md
Expand Up @@ -781,6 +781,22 @@ The base class `AbstractXtextCodeMiningProvider` provides some factory methods f
For an implementation reference, have a look at the Xtext Domainmodel example.
## UI Testing {#ui-testing}
Automated UI tests are crucial for the maintainability and the quality of a software product. That's why it is strongly recommended to write not only automated unit tests for your language, but also automated UI tests for your language editor. The `org.eclipse.xtext.ui.testing` package contains some base classes that come in handy when implementing automated UI tests:

* [AbstractAutoEditTest]({{site.src.xtext_eclipse}}/org.eclipse.xtext.ui.testing/src/org/eclipse/xtext/ui/testing/AbstractAutoEditTest.java): base class for testing the auto editing functionality
* [AbstractContentAssistTest]({{site.src.xtext_eclipse}}/org.eclipse.xtext.ui.testing/src/org/eclipse/xtext/ui/testing/AbstractContentAssistTest.xtend): base class for testing the content assistant and template proposals
* [AbstractFoldingTest]({{site.src.xtext_eclipse}}/org.eclipse.xtext.ui.testing/src/org/eclipse/xtext/ui/testing/AbstractFoldingTest.xtend): base class for testing the folding capabilities
* [AbstractHighlightingTest]({{site.src.xtext_eclipse}}/org.eclipse.xtext.ui.testing/src/org/eclipse/xtext/ui/testing/AbstractHighlightingTest.xtend): base class for testing the syntactical and semantic coloring
* [AbstractHoverTest]({{site.src.xtext_eclipse}}/org.eclipse.xtext.ui.testing/src/org/eclipse/xtext/ui/testing/AbstractHoverTest.xtend): base class for testing the hovering functionality
* [AbstractHyperlinkingTest]({{site.src.xtext_eclipse}}/org.eclipse.xtext.ui.testing/src/org/eclipse/xtext/ui/testing/AbstractHyperlinkingTest.xtend): base class for testing the hyperlinking functionality
* [AbstractOutlineTest]({{site.src.xtext_eclipse}}/org.eclipse.xtext.ui.testing/src/org/eclipse/xtext/ui/testing/AbstractOutlineTest.java): base class for testing the structure of the outline view
* [AbstractQuickfixTest]({{site.src.xtext_eclipse}}/org.eclipse.xtext.ui.testing/src/org/eclipse/xtext/ui/testing/AbstractQuickfixTest.xtend): base class for testing the quick fixes
* ...

The Xtext example projects (*File &rarr; New &rarr; Example &rarr; Xtext Examples*) contain UI test cases that make use of these framework classes. Feel free to study the corresponding `org.eclipse.xtext.example.<language>.ui.tests` projects to get some inspirations on how to implement automated UI test cases for your Xtext-based language editor.

---

**[Next Chapter: Web Editor Support](330_web_support.html)**

0 comments on commit 5470f7d

Please sign in to comment.