Parameter classes for @ContextConfiguration cannot be recognized

1.5k Views Asked by At

In the following test class

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import static org.junit.Assert.assertNotNull;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes=CDPlayerConfig.class)
public class CDPlayerTest {

    @Autowired
    private CompactDisc cd;

    @Test
    public void cdShouldNotBeNull(){
        assertNotNull(cd);
    }
}

compiler hightlights parameter classes in line

@ContextConfiguration(classes=CDPlayerConfig.class)

as an error. Class CDPlayerConfing is easily found.It is marked as Config class

@Configuration
@ComponentScan
public class CDPlayerConfig {
}

Do I miss some import?

1

There are 1 best solutions below

0
Krzysztof On

I found the solution. I have been using old Maven dependency for tests

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-test</artifactId>
        <version>3.0.5.RELEASE</version>
        <scope>test</scope>
    </dependency>

I've changed version for 5.0.1.RELEASE and it worked.