intellij-sdk-code-samples/reference_test.md
2015-04-14 10:36:40 +02:00

47 lines
973 B
Markdown

---
layout: editable
title: Reference Test
---
In this test we will check if references, implemented in the
[Reference Contributor](reference_contributor.html)
section of the
[Custom Language Support Tutorial](cls_tutorial.html),
works as we expect.
### 1. Define test data
Create a file *ReferenceTestData.java*.
```java
public class Test {
public static void main(String[] args) {
System.out.println("simple:website<caret>");
}
}
```
### 2. Define a test method
```java
public void testReference() {
myFixture.configureByFiles("ReferenceTestData.java", "DefaultTestData.simple");
PsiElement element = myFixture.getFile().findElementAt(myFixture.getCaretOffset()).getParent();
assertEquals("http://en.wikipedia.org/", ((SimpleProperty) element.getReferences()[0].resolve()).getValue());
}
```
### 3. Run the test
Run the test and make sure it's green.
-----
[Previous](commenter_test.html) [Top](writing_tests_for_plugins.html)