2

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?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Krzysztof
  • 129
  • 2
  • 11
  • How `CDPlayerConfig` is added to Spring? config class? xml configuration? can you show part of the code? – Ori Marko Dec 16 '18 at 09:10
  • It is marked with @Configuration annotation. I've edited the question. – Krzysztof Dec 16 '18 at 09:26
  • Why don't you have import of `CDPlayerConfig` in `CDPlayerTest`? – Ori Marko Dec 16 '18 at 09:29
  • I've added the import. It's grayed out, as non-used import. Still the same error during running test. Error:(14, 23) java: cannot find symbol symbol: method classes() location: @interface org.springframework.test.context.ContextConfiguration – Krzysztof Dec 16 '18 at 09:34

1 Answers1

1

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.

Krzysztof
  • 129
  • 2
  • 11