Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions docs/technical-reference/writing-extensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -343,3 +343,27 @@ Packages.com.google.refine.expr.MetaParser.registerLanguageParser(

The first string is the prefix that gets prepended to each expression so that we know which language the expression is in. This should be short, unique, and identifying. The second string is a user-friendly name of the language. The third is an object that implements the interface `com.google.refine.expr.LanguageSpecificParser`. The final string is the default expression in that language that would return the cell's value.

## Testing

Like OpenRefine core, extensions can test backend code through Java unit tests and frontend/integration tests can be written using Cypress. In addition to the resources below, extension authors are encouraged to review the documentation related to [functional tests](/docs/technical-reference/functional-tests) in OpenRefine core.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Like OpenRefine core, extensions can test backend code through Java unit tests and frontend/integration tests can be written using Cypress. In addition to the resources below, extension authors are encouraged to review the documentation related to [functional tests](/docs/technical-reference/functional-tests) in OpenRefine core.
We recommend extension authors write backend Java unit tests, like OpenRefine core does, and, if applicable, frontend/integration tests can be written using Cypress. In addition to the resources below, extension authors are encouraged to review the documentation related to [functional tests](/docs/technical-reference/functional-tests) in OpenRefine core.


Please note that Java unit tests can be run from the command line with no additional setup, but integration tests need to have a running instance of OpenRefine to test against.

### Java unit testing
The sample extension template includes a reference unit test suite which leverages [the `RefineTest` base class](https://github.com/OpenRefine/OpenRefine/blob/master/modules/core/src/test/java/com/google/refine/RefineTest.java) provided by OpenRefine core. Tests are not required to extend `RefineTest`, but that class provides many utilities that may help you test your extension.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The sample extension template includes a reference unit test suite which leverages [the `RefineTest` base class](https://github.com/OpenRefine/OpenRefine/blob/master/modules/core/src/test/java/com/google/refine/RefineTest.java) provided by OpenRefine core. Tests are not required to extend `RefineTest`, but that class provides many utilities that may help you test your extension.
The sample extension template includes a reference [unit test suite](https://github.com/OpenRefine/sample-extension/blob/master/src/test/java/com/google/refine/sampleExtension/SampleUtilTest.java) which leverages [the `RefineTest` base class](https://github.com/OpenRefine/OpenRefine/blob/master/modules/core/src/test/java/com/google/refine/RefineTest.java) provided by OpenRefine core. Tests are not required to extend `RefineTest`, but that class provides many utilities that may help you test your extension.


### End to end testing in Cypress
OpenRefine uses [Cypress](https://www.cypress.io/) to automate frontend and integration testing. To get started with end-to-end testing, [this guide in the Cypress docs](https://docs.cypress.io/app/end-to-end-testing/writing-your-first-end-to-end-test) may be helpful. The [documentation for OpenRefine's functional tests](/docs/technical-reference/functional-tests) also provides guidance for writing Cypress tests. For reference, please see the [Cypress tests in OpenRefine core](https://github.com/OpenRefine/OpenRefine/tree/master/main/tests/cypress) and the [Cypress tests in CommonsExtension](https://github.com/OpenRefine/CommonsExtension/tree/master/cypress).

When running Cypress tests, it is important to remember that the instance of OpenRefine being tested must have the [extension installed](/docs/manual/installing#installing-extensions). The `REFINE_DATA_DIR` environment variable is a helpful way of configuring the location of your extensions.

Cypress can also be run in headless mode, enabling end-to-end tests in CI/CD pipelines. The documentation for this feature can be found [on the Cypress website](https://docs.cypress.io/app/continuous-integration/overview) and an example script for running end-to-end tests can be found in [the `refine` shell script](https://github.com/OpenRefine/OpenRefine/blob/master/refine#L364-L443).

#### Testing OpenRefine with your extension installed
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SoryRawyer do you want to add here more details following your recent work?

Even without a dedicated test suite for the extension, Cypress tests can aid extension developers. The same setup above allows extension developers to run the core OpenRefine Cypress suite. This allows extension developers to confirm that their extension does not interfere with any core OpenRefine operations. Once again, install your extension in a dedicated test directory and start OpenRefine using that directory like so:
```
# note: your extension should be in a directory called "extensions" within this directory
REFINE_DATA_DIR=/path/to/your/test/directory ./refine
```

The Cypress tests can be run by following the remaining steps in the [functional tests documentation](/docs/technical-reference/functional-tests) and will now run against an OpenRefine instance that has your extension installed.