1

我最近开始使用 Spring Boot 1.4 和新的 Spring Boot 测试功能。

我正在将 spring-boot-starter-integration 与 Spring Boot 1.4.2.RELEASE 一起使用,并尝试使用新版本来测试我的存储库@DataJpaTest

当我运行我的测试时,我得到一个关于没有合格 bean 的异常。有问题的 beanhandler用于我的集成 bean。

如何在 JPA 测试期间排除集成运行?

应用类:

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ImportResource;

@SpringBootApplication
@ImportResource("integration.xml")
public class AutomateResultConsumerApplication {
    public static void main(String[] args) {
        SpringApplication.run(AutomateResultConsumerApplication.class, args);
    }
}

测试类:

@RunWith(SpringRunner.class)
@DataJpaTest
public class SampleHistoryRepositoryTest {
    @Autowired
    private TestEntityManager entityManager;

    @Autowired
    private SampleHistoryRepository sampleHistoryRepository;

    @Test
    public void findAllByObjectIdAndField() throws Exception {
        this.entityManager.persist(new SampleHistory(2L, "field", "somethingold", "somethingnew"));

        List<SampleHistory> sampleHistories = sampleHistoryRepository.findAllByObjectIdAndField(2L, "field", null);
        assertThat(sampleHistories.get(0).getOriginalValue()).isEqualTo("somethingold");
        assertThat(sampleHistories.get(0).getField()).isEqualTo("field");


    }
4

0 回答 0