Difference between revisions of "Database Testing"

From Developer Documents
Jump to navigation Jump to search
Line 5: Line 5:
 
*POJO JUnit tests, where tests are executed without OSGi and with some configuration restrictions
 
*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
 
*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 ==
 
== General ==
Line 30: Line 35:
  
 
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.
 
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.
 
The test framework can be found in org.simantics.db.testing. The framework contains
 
 
* Test case templates for extending in org.simantics.db.testing.base
 
* Generic test cases in org.simantics.db.testing.cases
 
  
 
== Running the tests ==
 
== Running the tests ==

Revision as of 11:30, 8 July 2011

Overview

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.

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.