8
@ContextConfiguration(classes = ConfigureCustomConfigurationModelProviderTest.class)
    public class ConfigureCustomConfigurationModelProviderTest extends AbstractContextTest {
        @Bean(name = "smth")
        public static ConfigurationModelProvider get() {
            return AnnotationConfigurationModelProvider.getInstance();
        }
        /*...*/
    }

I'm getting this error since migrating from junit4 to junit5. Why?

un1kalny
  • 81
  • 1
  • 6

2 Answers2

16

You should move every beans to @Configuration class for example TestConfig:

@Configuration
public class TestConfig {

    @Bean(name = "smth")
    public static ConfigurationModelProvider get() {
        return AnnotationConfigurationModelProvider.getInstance();
    }
}

and import it via @Import:

@Import({TestConfig.class})
@ContextConfiguration(classes = ConfigureCustomConfigurationModelProviderTest.class)
public class ConfigureCustomConfigurationModelProviderTest extends AbstractContextTest {
}
Kalle Richter
  • 8,008
  • 26
  • 77
  • 177
Amir Azizkhani
  • 1,662
  • 17
  • 30
0

To add to Amir's answer: if you only need the bean for some tests you can omit the @Configuration annotation at the top.

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
ferng001
  • 46
  • 6