我使用Maven,春数据源和单元使用ImpermanentGraphDatabase测试我的应用程序。 由于这是十分困难的设置它在这里是我做过什么:
在我的applicationContext.xml我初始化graphDatabaseService:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:neo4j="http://www.springframework.org/schema/data/neo4j"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/data/neo4j http://www.springframework.org/schema/data/neo4j/spring-neo4j-2.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"
default-lazy-init="true">
<neo4j:config graphDatabaseService="graphDatabaseService"/>
<!-- use in memory graph database -->
<bean id="graphDatabaseService" class="org.neo4j.test.ImpermanentGraphDatabase"/>
</beans>
在我的pom.xml
我不得不添加内核测试:
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-kernel</artifactId>
<version>1.6</version>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
否则非永久性图形数据库将不可用。
终于我可以用一个干净的图形数据库evrytime:
public class MyNeo4JTest extends TestCase {
protected ApplicationContext ctx;
protected GraphDatabaseService gds;
@Before
public void setUp() throws Exception {
// test-data
ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
gds = ctx.getBean(GraphDatabaseService.class);
}
@Test
public void testUser() {
...
}
}
我发现设置是比使用正常的方式更快。保持内存中的所有内容似乎都会得到回报
有一个现成的数据库可以为您做到这一点。使用ImpermanentGraphDatabase,它是仅限内存的,并且在创建新内存时始终保持清洁。这就是我们(Neo团队)用来测试我们自己的许多东西。 – Andres
我正在使用'ImpermanentGraphDatabase'进行集成/验收测试。也许这仍然是单元测试的方式。我将不得不查看该设置和拆卸的运行时成本。 –
有没有一种方法可以通过Nodejs访问它 - 只需通过REST API? –