[deepamehta-devel] Unittests for Deepamehta-Plugins

Robert Schuster robert.schuster.rs01 at gmail.com
Thu Nov 3 09:56:56 CET 2016


Hi guys and gals,
I'm concerned about software quality and I'd like to make it possible to
write simple unit tests for DM-plugins. I'd like to spend some
non-project time on this to improve the DM development.

Has anyone done any previous work on this that I should know about?

This is what I want to be able to do:

class DTOHelperTest {

public void test_storeMethod() {
   Topic t = DTOHelper.toComment(new JSONComment("Name", "Text", ...);

  Assert.assertEquals("blabla.somevalue", t.getTypeUri());
  Assert.assertEquals("Name",
t.getChildTopic().getSimpleValue("dm4.contact.person_name");
  …
}

}

For this to work I need to create a rather unique DM environment. Let me
know whether you see immediate problems with any of the following points:

(Let's call the DM-Plugin for which I want write the tests the
SUT-Plugin ('system under test'))
(Assume that the SUT-Plugin and DeepaMehta are in the same classpath)

 - configure DM programmatically (e.g. point DB folder to some /tmp-folder)
 - start DM (possibly with webclient included but without it opening a
browser)
 - register and run the SUT-Plugin, wait until it is completely initialized
 - (optionally) load JSON DB data by calling the REST-Interface of the
core-Plugin through Java
 - (before each test function): open a transaction
 - (after each test function): rollback transaction

Rolling back the transaction must guarantee that no changes have been
comitted to the DB. So that at the beginning of each test, the state of
the DB is the same. Is that possible?

I am wondering how I would have to start something like this. Does the
following sound good?
* programmatically set up a Felix OSGi container
* put DM into the container
* provide complete config for DM
* put SUT-Plugin to the container
* start the container

I am thinking of checking out DM sources soon and propose changes to
internal API to get this working in case something blocks this work.

What are you guys thinking? Any major roadblocks on this way?

The outlook of this project is, that all Java-based DM-Plugins can have
regression tests easily and we can use stuff like SonarQube etc. to
determine code quality metrics. The next step would be to allow unit
tests in DM-core as well.

All the best,
Robert

-- 
Robert Schuster
freiberuflicher Softwareingenieur

RS01 - IT-Systemanalyse und -entwicklung Robert Schuster
Brückenstraße 4 • 12439 Berlin
+49 157 798 00 310
robert.schuster.rs01 at gmail.com




More information about the devel mailing list