I have been working on new unit tests for the Jena project.  I have
completed a first pass on most of the core functionality.  I would like a
couple of developers to try out the new tests on their code as I would like
some feedback before continuing much farther.

These test classes use the junit-contracts framework (
https://github.com/Claudenw/junit-contracts) which uses annotations to
identify test classes that are tests for interfaces (Contract tests) and
executes them against concrete implementations of the interface.

You can create a test for your graph implementation, called MyGraph in the
example, by doing the following:

import org.junit.runner.RunWith;
import org.xenei.junit.contract.Contract;
import org.xenei.junit.contract.ContractImpl;
import org.xenei.junit.contract.ContractSuite;
import org.xenei.junit.contract.IProducer;
import com.hp.hpl.jena.testing_framework.AbstractGraphProducer;

@RunWith(ContractSuite.class)
@ContractImpl(MyGraph.class)  // the class under test.
public class MyGraphTest {

// AbstractGraphProducer will automatically call close() on each graph when
it is finished.
  // however if you have special clean up requriements will want to
implement afterClose()
// see AbstractGraphProducer class for more info
protected IProducer<MyGraph> graphProducer = new
AbstractGraphProducer<MyGraph>() {

@Override
protected MyGraph createNewGraph() {
return new MyGraph(); // create a new instance of MyGraph here
}

};

@Contract.Inject
public IProducer<MyGraph> getGraphProducer() {
return graphProducer;
}

// additional MyGraph specific tests go here
@Test
public void myGraphSpecificTest1() {
....
}

}

Since MyGraph implements Graph the GraphContractTest test methods will be
added to the suite.

The junit-contract suite handles locating contract tests for implemented
interfaces and adding them to the suite.

This should ensure that all implementation meet the contract requirements.

For example whenever graph.add() is called the graph implementation should
notify all the listeners.  This is checked by the GraphContractTest.   This
solution should provide a simple means for developers to test their
implementations.

Currently the com.hp.hpl.jena.graph package and the
 com.hp.hpl.jena.rdf.model packages have tests.

Much of the junit v3 test hierarchy is not in the new-test package.

Claude
-- 
I like: Like Like - The likeliest place on the web<http://like-like.xenei.com>
LinkedIn: http://www.linkedin.com/in/claudewarren

Reply via email to