0

I'm trying to do a test on the repository using @DataJPATest but @Autowired is not working I already tried looking for examples of junit5 with @DataJpaTest, but I didn't find it

I tried adding other dependencies, I used @SpringTest and it worked, but I wanted to use @DataJpaTest

package com.projetoSpring.catalog.repositories;

import com.projetoSpring.catalog.model.Product;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;

import java.util.Optional;

@DataJpaTest
public class ProductRepositoryTests {

    @Autowired
    private ProductRepository repositorys;

    @Test
    public void deleteShouldDeleteObjectWhenIdExists() {

        long exintingId = 1L;

        repositorys.deleteById(exintingId);

        Optional<Product> result = repositorys.findById(1L);
        Assertions.assertFalse(result.isPresent());
    }
}



org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'com.projetoSpring.catalog.repositories.ProductRepositoryTests': Unsatisfied dependency expressed through field 'repositorys'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.projetoSpring.catalog.repositories.ProductRepository' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

1 Answers1

0

I managed to solve it, I updated spring to version 2.7.5 and I verified that the test dependency was not downloading correctly, I redid the pom.xml and it worked.