Sha
Sha

Reputation: 1191

UnsatisfiedDependencyException for @DataNeo4jTest

I try to test my code with Spring-Boot Neo4j but I've got an error like org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'com.sha.neo4j.service.UserServiceTest': Unsatisfied dependency expressed through field 'userService'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.sha.neo4j.service.UserService' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

Dependencies;

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-data-neo4j'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    compileOnly 'org.projectlombok:lombok'
    annotationProcessor 'org.projectlombok:lombok'
    testImplementation('org.springframework.boot:spring-boot-starter-test') {
        exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
    }
    testImplementation 'org.neo4j.test:neo4j-harness:4.0.0'
    testImplementation 'org.neo4j:neo4j-ogm-embedded-driver:3.2.8'
}

And test class;

@RunWith(SpringRunner.class)
@DataNeo4jTest
public class UserServiceTest
{
    @Autowired
    private UserService userService;

    @Test
    public void testIt()
    {
        User user = new User();
        user.setLastName("Test");
        user.setName("Test");
        userService.saveUser(user);

        List<User> users = userService.findAll();

        assertThat(users).hasSize(1);
    }
}

In here, I've jus try to test above code with embedded driver but I've got an error like above. I don't have a specific properties (test application.properties) for test. Test works with neo4j-desktop bolt driver.

Is there any suggestion?

Upvotes: 0

Views: 269

Answers (1)

ahmkara
ahmkara

Reputation: 907

You should use @SpringBootTest over your tests. @DataNeo4jTest doesn't load any required services.

Upvotes: 2

Related Questions