0
我正在使用Spring 4.3.3.RELEASE
,Hibernate 5.0.11.Final
,JUnit 4.1.2
,SDN4.1.3-RELEASE
和neo4j-ogm-2.0.5
。我阅读并尝试实施@DirtyContext
,这可以在每个测试方法结束运行后重置我的数据库。但是当我查看我的数据库时,我在Test方法中创建的所有节点仍然存在。JUnit - @DirtyContext在每种测试方法后都不重置neo4j数据库
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = MockApplication.class)
@ContextConfiguration(classes = TestConfig.class)
@DirtiesContext(classMode=ClassMode.AFTER_EACH_TEST_METHOD)
public class OrderServiceTest {
@Autowired
private OrderService orderService;
@Autowired
private CustomerService customerService;
@Autowired
private TableService tableService;
@Test
public void orderMenuFoodAndDrink() throws Exception {
Customer customer = new Customer();
customer.setName("Customer 1");
customerService.save(customer);
Table table = new Table();
table.setCustomer(customer);
tableService.save(table);
ObjectResult result = orderService.orderTable(customer.getId());
assertThat(result.getTables().get(0), is(table`enter code here`));
}
}
这是我如何设置我的配置背景与Java注释
@Configuration
public class TestConfig {
@Primary
@Bean
public OrderService OrderService() {
OrderService OrderService = new OrderServiceImpl();
return OrderService;
}
}
OrderService
是我的接口类,并OrderServiceImpl
是我服务的实现。我有两个引用,但所有这些不工作,因为当我看着自己的数据库,所有节点仍然存在,不会被删除
哦我的..我想这个..谢谢@Jobin –
而对于信息,我不需要ContextCo配置,只需使用Transactional和DirtyContext,对我来说已经很好。 –