如何测试React式mongo存储库?

yrdbyhpb  于 2021-07-13  发布在  Java
关注(0)|答案(1)|浏览(260)

我想测试一下 findByPhoneNumber 方法

public interface UserRepository extends ReactiveMongoRepository<User, String> {

    Mono<User> findByPhoneNumber(String phoneNumber);

}

自动取款机,我的测试像这样

@ExtendWith(SpringExtension.class)
class UserRepositoryTest {

    @Autowired
    private UserRepository repository;

    @Test
    void findByPhoneNumber() {
        val phoneNumber = "11111 111111";

        val user = repository.save(User.builder().phoneNumber(phoneNumber).password("password").build());

        assertEquals(user, repository.findByPhoneNumber(phoneNumber));
    }

}

当我运行它,我得到这个错误 org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'io.freesale.repository.UserRepositoryTest': Unsatisfied dependency expressed through field 'repository'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'io.freesale.repository.UserRepository' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)} 我是个蠢货,所以请不要太欺负我?

相关问题