lundi 1 mai 2017

Limiting entities loaded with @DataJpaTest

I am using spring boot 1.5.3 and spring data jpa. I am writing a test of a single entity and repository against an embedded H2 database. There are almost 100 entities in present.

I have created the test based upon the sprint boot example which uses @DataJpaTest.

When I run a test it automatically drops and creates all the 100 entities, which is slow. How can I limit it to the one entity I am testing?

I have experimented with the excludeFilters, includeFilters and useDefaultFilters of @DataJpaTest to no affect.

Here is the guts of the test:

@RunWith(SpringRunner.class)
@SpringBootTest
@DataJpaTest
public class RepositoryITests {

    @Autowired
    private StatusRepository statusRepository;

    @Test
    public void statuses() {

        assertThat( this.statusRepository.findById(-1 ) , is( nullValue () ));

Thanks in advance.

Aucun commentaire:

Enregistrer un commentaire