java - Function works in main class but not it test class -
i have class compiles , runs expected (adds 1 test node per execution):
public class reqsdb { private final string store_dir; public graphdatabaseservice graphdb; private static enum reltypes implements relationshiptype { identifies, satifies } public reqsdb(string dbpath) { store_dir = dbpath; graphdb = new graphdatabasefactory().newembeddeddatabase(store_dir); registershutdownhook(graphdb); } public void createtestnode() { transaction tx = graphdb.begintx(); node newnode; try { newnode = graphdb.createnode(); newnode.setproperty("test", "test"); tx.success(); } { tx.finish(); } } private static void registershutdownhook(final graphdatabaseservice graphdb) { runtime.getruntime().addshutdownhook(new thread() { @override public void run() { graphdb.shutdown(); } }); } void shutdown() { graphdb.shutdown(); } public static void main(string[] args) { reqsdb testdb = new reqsdb("target/testdb"); testdb.createtestnode(); } }
however test function, testcreatetestnode() causes error:
java.lang.runtimeexception: org.neo4j.kernel.lifecycle.lifecycleexception: component 'org.neo4j.kernel.storelockerlifecycleadapter@4e3a2be1' initialized, failed start.
since function works called main(), think there wrong test class.
package com.github.dprentiss; import junit.framework.test; import junit.framework.testcase; import junit.framework.testsuite; public class reqsdbtest extends testcase { protected reqsdb testdb = new reqsdb("target/testdb"); public reqsdbtest(string testname) { super(testname); } public static test suite() { return new testsuite(reqsdbtest.class); } public void testdbservice() { assertnotnull(testdb); } public void testcreatetestnode() { testdb.createtestnode(); } public void teardown() { testdb.shutdown(); }
is there wrong test set up?
try put
protected reqsdb testdb = new reqsdb("target/testdb");
in init method . follow example:
Comments
Post a Comment