How to implement deletion in Junit with Spring Boot?

0

I need to know how to implement registry exclusion through Junit (Unit Testing) with Spring Boot, I'm having difficulty, the inclusion is working as you can see below;

@Autowired
    private PessoaRepository pessoaRepository;

    @Autowired
    private PessoaService pessoaService;

    @Test
    public void testAdicionarPessoa() throws Exception {
        Pessoa pessoa1 = new Pessoa("Douglas", "399.536.640-64");
        this.pessoaService.salvar(pessoa1);
        // Assertions.assertThat(pessoa1.getName()).isNotNull();
    }

I tried to delete the registry this way, but I did not succeed.

@Test
    public void testeDeletePessoa() throws Exception {
        Pessoa pessoa2 = new Pessoa();
        this.pessoaRepository.delete((long) 4);

    }

I accept suggestions and am open to questions

Attempting to insert code generated this error;

    
asked by anonymous 02.11.2018 / 13:23

1 answer

0

The error is giving because it is not finding in the database a record with an id 4 for deletion.

You've probably already run the test once and you've excluded the record.

One solution to this type of problem is the use of databases that are run in memory for testing, ie the database only works while the application is running, for example H2 or HSQLDB.

Here are some companion links:

link

link

    
02.11.2018 / 14:08