Database Testing

From Developer Documents
Jump to: navigation, search

Overview

The testing framework is contained in the plug-in org.simantics.db.testing

This section covers a JUnit-based testing framework for making tests, which use the Simantics Database. The framework handles two separate cases

  • POJO JUnit tests, where tests are executed without OSGi and with some configuration restrictions
  • OSGi JUnit tests, where tests are executed in OSGi based on the current workspace

The framework contains

  • Test case templates for extending in org.simantics.db.testing.base
  • Generic test cases in org.simantics.db.testing.cases

General

Both testing approaches use similar test suites. Below is an example

public class Tests {

    public static Test suite() throws Exception {

        TestSuite suite = new TestSuite("My suite");
	    
        //$JUnit-BEGIN$
        suite.addTestSuite(FreshDatabaseTest.class);
        suite.addTestSuite(MyTest.class);

        //$JUnit-END$
        return suite;

    }

}

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.

Templates

FreshDatabaseTest

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.

ExistingDatabaseTest

This test can be used to run tests upon an existing database (created e.g. with FreshDatabaseTest). Use getSession() for obtaining the session.

WriteReadTest

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.

Running the tests

To run the tests open a context menu for the suite class (see example above) and

  • To run in POJO, select Run As .. JUnit Test
  • To run in OSGi, select Run As .. JUnit Plug-in Test

The Plug-in tests need to be run as 'all workspace and enabled target plug.ins' and as application '[No Application] - Headless Mode]'

Note that the launchers can be configured using .launch - files.

POJO details

The POJO testing framework can be set up by running a customized org.simantics.db.testing.cases.FreshDatabaseTest e.g.

public class InitializationTest extends FreshDatabaseTest {

    @Override
    public void configure(TestSettings settings) {
		
        settings.setAdapters(new String[] { 
            "org.simantics.db.layer0/adapters.xml",
            "org.simantics.spreadsheet.graph/adapters.xml" 
        });
        settings.setOntologies(new String[] { 
            "/org.simantics.spreadsheet.ontology/graph.tg",
        });
		
        settings.setWorkspace(new File(".."));
        settings.setInitialized();
		
    }
	
}

OSGi details

The Plug-in testing framework applies all adapters found from the workspace.

org.simantics.db.testing.cases.FreshDatabaseTest can be used to install all available ontologies from the workspace.