java - Annotation @SpringBootTest and launching a single class test with IDEA embedded JUnit runner instead of maven test goal -

I have a Java Test class using spring boot test :@ExtendWith(SpringExtension.class)@SpringBootTest(we

I have a Java Test class using spring boot test :

@ExtendWith(SpringExtension.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = LvgMainTest.class) 
@ActiveProfiles(value = {"integration-test", "test"})
public class ProduitsApiImplTest {

    @Autowired
    private TestRestTemplate restTemplate;

    @Test
    public void testListProduits_200_OK() {
        Produit produitExpected = new Produit();
        produitExpected.setId(1L);
        produitExpected.setCode("FFL");
        produitExpected.setLibelle("premierProduit");
        ResponseEntity<ProduitSk[]> response = this.restTemplate.getForEntity("/produits?nomOuCode=premier", ProduitSk[].class);
        assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
        assertThat(response.getBody()).isNotEmpty();
        assertThat(response.getBody().length).isEqualTo(1);
        assertProduit(response.getBody()[0], produitExpected);
    }

When I run mvn test command through IDEA running "maven" configuration (with goal test). My test passes ! But When I use in the editor the arrow in the margin at the left of the class name, I.E. running with embedded IDEA Junit, I've got the error :

java.lang.IllegalStateException: Failed to load ApplicationContext for [WebMergedContextConfiguration@538d2308 testClass = fr.lvg.ProduitsApiImplTest, locations = [], classes = [fr.lvg.LvgMainTest], contextInitializerClasses = [], activeProfiles = ["integration-test", "test"], propertySourceDescriptors = [], propertySourceProperties = [".springframework.boot.test.context.SpringBootTestContextBootstrapper=true", "server.port=0"], contextCustomizers = [[ImportsContextCustomizer@3d0697da key = [config.ConfigTest]], .springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@79dc5318, .springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@54eb2b70, .springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, .springframework.boot.test.web.client.TestRestTemplateContextCustomizer@50de186c, .springframework.boot.test.web.reactorty.DisableReactorResourceFactoryGlobalResourcesContextCustomizerFactory$DisableReactorResourceFactoryGlobalResourcesContextCustomizerCustomizer@36cda2c2, .springframework.boot.test.autoconfigure.OnFailureConditionReportContextCustomizerFactory$OnFailureConditionReportContextCustomizer@5b367418, .springframework.boot.test.autoconfigure.actuate.observability.ObservabilityContextCustomizerFactory$DisableObservabilityContextCustomizer@1f, .springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@0, .springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizer@172b013, .springframework.boot.test.context.SpringBootTestAnnotation@e306c040], resourceBasePath = "src/main/webapp", contextLoader = .springframework.boot.test.context.SpringBootContextLoader, parent = null]

    at .springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:180)
    at .springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:130)
    at .springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.j
    ....
    Caused by: .springframework.beans.factory.BeanCreationException: Error creating bean with name 'IProduitMapperImpl' defined in file [D:\travail\workspace-lvg\levidegrenier\lvg-service-impl\target\classes\fr\lvg\mapper\IProduitMapperImpl.class]: Failed to instantiate [fr.lvg.mapper.IProduitMapperImpl]: Constructor threw exception
    at .springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1337)
    at .springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1222)
    ...
    Caused by: .springframework.beans.BeanInstantiationException: Failed to instantiate [fr.lvg.mapper.IProduitMapperImpl]: Constructor threw exception
    at .springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:221)
    ...
Caused by: java.lang.Error: Unresolved compilation problems: 
    IProduitMapper cannot be resolved to a type
    The method produitSkToProduit(ProduitSk) of type IProduitMapperImpl must override or implement a supertype method
    The method produitToProduitSk(Produit) of type IProduitMapperImpl must override or implement a supertype method

    at fr.lvg.mapper.IProduitMapperImpl.<init>(IProduitMapperImpl.java:14)
    at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:502)
    at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:486)
    at .springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:195)
    ... 42 more

Can you explain to me why and what to do so the SpringBoot container will start in any case : mvn test or junit running. It seems classpath are not the same according to the launcher (mvn test or junit embbedded). Thanks for your explanantions.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742367332a4430575.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信