Проблема с тестированием Hibe rnet с использованием Junit в Spring Boot - PullRequest
0 голосов
/ 23 февраля 2020

Я хочу проверить слой данных Spring у меня есть базовый c @Entity Продукты:

@Entity
@Table(name = "products")
@JsonIgnoreProperties({ "hibernateLazyInitializer", "handler" })
public class Product{

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "i_user")
    private int id;

    @Column(name = "user_name")
    private String userName;

У меня есть ProductRepository Репозиторий:

public interface ProductRepository extends JpaRepository<Product, Integer> {

}

И у меня есть test ProductTest:

@RunWith(SpringRunner.class)
@DataJpaTest
public class ProductTest{

    @Autowired
    private ProductRepository  productRepository;

    @Test
    public void test() {

        List<Product> users = productRepository.findAll();

        assertThat(users).hasSize(1);

    }
}

И у меня эта ошибка:

18:53:15.926 [main] DEBUG org.springframework.test.context.junit4.SpringJUnit4ClassRunner - SpringJUnit4ClassRunner constructor called with [class com.ProductTest]
18:53:15.942 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating CacheAwareContextLoaderDelegate from class [org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate]
18:53:15.954 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating BootstrapContext using constructor [public org.springframework.test.context.support.DefaultBootstrapContext(java.lang.Class,org.springframework.test.context.CacheAwareContextLoaderDelegate)]
18:53:15.987 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating TestContextBootstrapper for test class [com.ProductTest] from class [org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTestContextBootstrapper]
18:53:16.012 [main] INFO org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTestContextBootstrapper - Neither @ContextConfiguration nor @ContextHierarchy found for test class [com.ProductTest], using SpringBootContextLoader
18:53:16.020 [main] DEBUG org.springframework.test.context.support.AbstractContextLoader - Did not detect default resource location for test class [com.ProductTest]: class path resource [com/ProductTest-context.xml] does not exist
18:53:16.021 [main] DEBUG org.springframework.test.context.support.AbstractContextLoader - Did not detect default resource location for test class [com.ProductTest]: class path resource [com/ProductTestContext.groovy] does not exist
18:53:16.022 [main] INFO org.springframework.test.context.support.AbstractContextLoader - Could not detect default resource locations for test class [com.ProductTest]: no resource found for suffixes {-context.xml, Context.groovy}.
18:53:16.023 [main] INFO org.springframework.test.context.support.AnnotationConfigContextLoaderUtils - Could not detect default configuration classes for test class [com.ProductTest]: ProductTest does not declare any static, non-private, non-final, nested classes annotated with @Configuration.
18:53:16.134 [main] DEBUG org.springframework.test.context.support.ActiveProfilesUtils - Could not find an 'annotation declaring class' for annotation type [org.springframework.test.context.ActiveProfiles] and class [com.ProductTest]
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...