如何在弹簧数据neo4j(SDN5)中加载夹具数据集进行集成测试



我想在一个项目中编写集成测试,该项目在(非web(spring引导应用程序的上下文中使用spring数据neo4j版本5(SDN5(。对于集成测试,我想在每次测试之前导入一个定义的数据集,以获得图形数据库的初始起点(fixture(,但我不知道如何加载它。有人知道如何加载吗?

我使用的是neo4j 3.4.3、SDN5、Spring Boot 2.0、JUnit 5.1。

我通常通过对嵌入式实例运行和执行集成测试

@ExtendWith(SpringExtension.class)
@DataNeo4jTest(
excludeFilters = @ComponentScan.Filter(
type = FilterType.ASSIGNABLE_TYPE, value = ApplicationRunner.class
)
)
@ComponentScan(basePackageClasses = {TransformationService.class})
@ActiveProfiles("test")
class Neo4jAgentAutomatonTest {
@Test
void getStates() {
...
}
}

a(当您还将neo4j-ogm-test添加到项目中时,它将为您提供TestUtils类。这个类的方法readCQLFile解析文件并返回密码查询。

b( 您也可以在没有这种依赖关系的情况下自行读取该文件。

最后,您在类中添加了一个SessionFactory依赖项作为autowired,并执行生成的查询

class Test {
@Autowired
private SessionFactory sessionFactory;
@Before
public void setUp() {
Session session = sessionFactory.openSession();
session.query(               
TestUtils.readCQLFile("<filePath>").toString(), emptyMap());
// ....
}
}

最新更新