Pepper
3.3.3-SNAPSHOT
A highly extensible plattform for conversion and manipulationoflinguisticdata.
|
Pepper helps you to write test code faster by providing a test suite skeleton (the three classes org.corpus_tools.pepper.testFramework.PepperManipulatorTest, org.corpus_tools.pepper.testFramework.PepperImporterTest and org.corpus_tools.pepper.testFramework.PepperExporterTest). These classes use the JUnit test framework (see: junit.org) and implement some very basic tests for checking the consistency of a Pepper module. Just benefit from these classes by creating an own test class derived from one of them and your tests will be ran during the Maven build cycle. For getting an immediate feedback, you can also run them directly in your development environment by running a JUnit task. On the one hand the test classes provide tests which can be adapted to your needs and check if your module can be plugged into the Pepper framework (by checking if necessary values are set like the supported format for an im- or exporter). And on the other hand, they provide some helper classes and functions, which can be used when adding further test methods for checking the functionality of your module.
Note
We strongly recommend to add some module specific test methods, to increase the quality of your code and even to make it easier changing things and still having a correctly running module.
To set up the tests for the JUnit framework override the method setUp() as shown in the following snippet:
Since the JUnit framework can not know about the classes to test, you need to set and initialize it as shown on position 1. In case you are implementing an im- or exporter, you need to set the supported formats and versions in your test case. Pepper will check them automatically, but the test environment needs to know the correct pairs of format name and version. Replace FORMAT_NAME and FORMAT_VERSION with your specific ones. You can even add more than one org.corpus_tools.pepper.common.FormatDesc object.
The provided test classes emulate the Pepper environment, so that you can run your entire module and just check the in- or output.
If you write an importer, you can create an input file containing a corpus in the format you want to support, run your importer and check its output against a predefined template. The test will return a processed Salt model which can be checked for its nodes, relations and so on. The following snippet shows how to read a document and how to check the returned Salt model:
If your test does not extend PepperModuleTest
or either of its sub-classes, you will also have to add an SCorpusGraph
to the module's SaltProject
:
//create an empty corpus graph, which is filled by your module SCorpusGraph importedSCorpusGraph= SaltFactory.createSCorpusGraph(); // add the corpus graph to your module getFixture().getSaltProject().addCorpusGraph(importedSCorpusGraph);
develop
More samples for testing can be found in the automatically generated test classes when using Pepper's archetype for Maven, see Tutorial: Getting started in 10 minutes.
For testing an exporter, you may want to use Salt's sample generator (org.corpus_tools.salt.samples.SampleGenerator). Here you will find a lot of methods creating a sample Salt model with the possibility to just create the layers, you want to use. For more information, take a look into Salt's api.
The class org.corpus_tools.pepper.testFramework.PepperTestUtil provides some very helpful methods like org.corpus_tools.pepper.testFramework.PepperTestUtil.getSrcResources() to get a reference to the resources folder (./src/main/resources) or the method getTestResources to get a reference to the test resource folder (./src/test/resources).
When you are implementing an importer and an exporter you may want to make sure that no data is lost, you can orchestrate the im- and the exporter and compare the input files with the output files. In that case implementing the classes org.corpus_tools.pepper.testFramework.PepperImporterTest and org.corpus_tools.pepper.testFramework.PepperExporterTest won't do the job, because they assume that you are testing a single module. To load multiple modules in the Pepper test environment, use the method org.corpus_tools.pepper.testFramework.PepperTestUtil.start(Collection<PepperModule> fixtures) instead and pass your im- and your exporter.
To test whether the self-test is working or not, you can run it as a JUnit test as follows:
To learn more about the self-test please check selftest