3 The testing framework is contained in the plug-in **org.simantics.db.testing**.
\r
5 This section covers a JUnit-based testing framework for making tests, which use the Simantics Database. The framework handles two separate cases
\r
7 * POJO JUnit tests, where tests are executed without OSGi and with some configuration restrictions
\r
8 * OSGi JUnit tests, where tests are executed in OSGi based on the current workspace
\r
10 The framework contains
\r
12 * Test case templates for extending in org.simantics.db.testing.base
\r
13 * Generic test cases in org.simantics.db.testing.cases
\r
17 Both testing approaches use similar test suites. Below is an example
\r
20 public class Tests {
\r
22 public static Test suite() throws Exception {
\r
24 TestSuite suite = new TestSuite("My suite");
\r
27 suite.addTestSuite(FreshDatabaseTest.class);
\r
28 suite.addTestSuite(MyTest.class);
\r
38 The first test is used to set up the initial database and upon which the other tests operate. In POJO mode the first test also needs to give some configuration settings as described below.
\r
42 ### FreshDatabaseTest
\r
44 This test can be used to initialize a database with only selected ontologies installed. The test can be run as is or it can be extended to perform tests upon the initialized database. Use getSession() for obtaining the session.
\r
46 ### ExistingDatabaseTest
\r
48 This test can be used to run tests upon an existing database (created e.g. with FreshDatabaseTest). Use getSession() for obtaining the session.
\r
52 This test can be used to run simple write-first-then-read tests upon an existing database. Override methods write and read to perform testing.
\r
54 ## Running the tests
\r
56 To run the tests open a context menu for the suite class (see example above) and
\r
58 * To run in POJO, select Run As .. JUnit Test
\r
59 * To run in OSGi, select Run As .. JUnit Plug-in Test
\r
61 The Plug-in tests need to be run as 'all workspace and enabled target plug.ins' and as application '[No Application] - Headless Mode]'
\r
63 Note that the launchers can be configured using .launch - files.
\r
67 The POJO testing framework can be set up by running a customized org.simantics.db.testing.cases.FreshDatabaseTest e.g.
\r
70 public class InitializationTest extends FreshDatabaseTest {
\r
73 public void configure(TestSettings settings) {
\r
75 settings.setAdapters(new String[] {
\r
76 "org.simantics.db.layer0/adapters.xml",
\r
77 "org.simantics.spreadsheet.graph/adapters.xml"
\r
79 settings.setOntologies(new String[] {
\r
80 "/org.simantics.spreadsheet.ontology/graph.tg",
\r
83 settings.setWorkspace(new File(".."));
\r
84 settings.setInitialized();
\r
93 The Plug-in testing framework applies all adapters found from the workspace.
\r
95 org.simantics.db.testing.cases.FreshDatabaseTest can be used to install all available ontologies from the workspace.
\r