Я не могу выполнить mvn-тест весенней загрузки ⇐ JAVA
Я не могу выполнить mvn-тест весенней загрузки
Я использовал vscode для создания программы Springboot для подключения к API Finnhub, но она показала следующие ошибки:
\[ОШИБКА\] CompanyServiceTest.testFindAll ? IllegalState Не удалось загрузить ApplicationContext для \[WebMergedContextConfiguration@6c3884f5 testClass = com.hkjava.demo.demofinnhub.CompanyServiceTest, Locations = \[\], классы = \[com.hkjava.demo.demofinnhub.DemoFinnhubApplication\], contextInitializerClasses = \[ \], activeProfiles = \[\], propertySourceLocations = \[\], propertySourceProperties = \["org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true"\], contextCustomizers = \[org.springframework.boot.test , org.springframework.boot.test.web .client.TestRestTemplateContextCustomizer@7fc4780b, org.springframework.boot.test.autoconfigure.actuate.observability.ObservabilityContextCustomizerFactory$DisableObservabilityContextCustomizer@1f, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@0, org. Springframework.boot.test .autoconfigure.web.servlet.WebDriverContextCustomizer@59d4cd39, org.springframework.boot.test.context.SpringBootTestAnnotation@8fbf833d\], resourcesBasePath = "src/main/webapp", contextLoader = org.springframework.boot.test.context.SpringBootContextLoader , родитель = ноль\] \[ОШИБКА\] CompanyServiceTest.testUrl1ByUri ? IllegalState Не удалось загрузить ApplicationContext для \[WebMergedContextConfiguration@6c3884f5 testClass = com.hkjava.demo.demofinnhub.CompanyServiceTest, Locations = \[\], классы = \[com.hkjava.demo.demofinnhub.DemoFinnhubApplication\], contextInitializerClasses = \[ \], activeProfiles = \[\], propertySourceLocations = \[\], propertySourceProperties = \["org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true"\], contextCustomizers = \[org.springframework.boot.test , org.springframework.boot.test.web .client.TestRestTemplateContextCustomizer@7fc4780b, org.springframework.boot.test.autoconfigure.actuate.observability.ObservabilityContextCustomizerFactory$DisableObservabilityContextCustomizer@1f, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@0, org. Springframework.boot.test .autoconfigure.web.servlet.WebDriverContextCustomizer@59d4cd39, org.springframework.boot.test.context.SpringBootTestAnnotation@8fbf833d\], resourcesBasePath = "src/main/webapp", contextLoader = org.springframework.boot.test.context.SpringBootContextLoader , родитель = ноль\] \[ОШИБКА\] DemoFinnhubApplicationTests.contextLoads? IllegalState Не удалось загрузить ApplicationContext для \[WebMergedContextConfiguration@2bd8c8f1 testClass = com.hkjava.demo.demofinnhub.DemoFinnhubApplicationTests, location = \[\], классы = \[com.hkjava.demo.demofinnhub.DemoFinnhubApplication\], contextInitializerClasses = \[ \], activeProfiles = \[\], propertySourceLocations = \[\], propertySourceProperties = \["org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true"\], contextCustomizers = \[org.springframework.boot.test .context.filter.ExcludeFilterContextCustomizer@352ff4da, org.springframework.boot.test.json.DuulateJsonObjectContextCustomizerFactory$DucateJsonObjectContextCustomizer@295cf707, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework .boot.test.web .client.TestRestTemplateContextCustomizer@7fc4780b, org.springframework.boot.test.autoconfigure.actuate.observability.ObservabilityContextCustomizerFactory$DisableObservabilityContextCustomizer@1f, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@0, org. Springframework.boot.test .autoconfigure.web.servlet.WebDriverContextCustomizer@59d4cd39, org.springframework.boot.test.context.SpringBootTestAnnotation@8fbf833d\], resourcesBasePath = "src/main/webapp", contextLoader = org.springframework.boot.test.context.SpringBootContextLoader , родитель = ноль\] Код файла показан ниже:
// CompanyServiceTest импортировать статический org.hamcrest.MatcherAssert.assertThat; импортировать статический org.hamcrest.Matchers.equalTo; импортировать статический org.hamcrest.Matchers.hasItem; импортировать статический org.hamcrest.Matchers.hasProperty; импортировать статический org.hamcrest.Matchers.not; импортировать java.time.LocalDate; импортировать java.util.List; импортировать org.junit.jupiter.api.Test; импортировать org.mockito.Mockito; импортировать org.springframework.beans.factory.annotation.Autowired; импортировать org.springframework.boot.test.context.SpringBootTest; импортировать org.springframework.boot.test.mock.mockito.MockBean; импортировать org.springframework.web.client.RestTemplate; импортировать com.hkjava.demo.demofinnhub.entity.Stock; импортировать com.hkjava.demo.demofinnhub.Exception.FinnhubException; импортировать com.hkjava.demo.demofinnhub.model.CompanyProfile; импортировать com.hkjava.demo.demofinnhub.repository.StockRepository; импортировать com.hkjava.demo.demofinnhub.service.CompanyService; @SpringBootTest общественный класс CompanyServiceTest { @MockBean частный StockRepository StockRepository; @MockBean частный RestTemplate restTemplate; @Autowired частная строка finnhubToken; @Autowired частная компанияСервисная компанияСервис; // Hamcrest, hasItem() -> тестовый массив @Тест недействительный testFindAll() { Stock stock1 = Stock.builder().id(1L).country("США").build(); Stock stock2 = Stock.builder().id(2L).country("CN").build(); Mockito.when(stockRepository.findAll()).thenReturn(List.of(stock1, stock2)); List stocks = CompanyService.findAll(); // вызов stockRepository.findAll() AssertThat(акции, hasItem(hasProperty("страна", равныйTo("CN")))); AssertThat(stocks, hasItem(hasProperty("country", равныйTo("США")))); AssertThat(акции, not(hasItem(hasProperty("country", равныйTo("HK"))))); } @Тест void testUrl1ByUri() выдает FinnhubException { Ожидаемая строкаUrl = "https://finnhub.io/api/v1/stock/profile ... APL&token=" .concat(finnhubToken); CompanyProfile издеваетсяCompanyProfile = CompanyProfile.builder() // .country("США") // .ipoDate(LocalDate.of(1988, 12, 31)) // .строить(); Mockito.when(restTemplate.getForObject(expectedUrl, CompanyProfile.class)) .thenReturn(mockedCompanyProfile); Профиль компании = CompanyService.getCompanyProfile("AAPL"); // вызов stockRepository.findAll() AssertThat(profile, hasProperty("страна", равныйTo("США"))); } } // DemoFinnhubApplicationTests импортировать org.junit.jupiter.api.Test; импортировать org.springframework.boot.test.context.SpringBootTest; @SpringBootTest класс DemoFinnhubApplicationTests { @Тест недействительный contextLoads () { } } Как я могу решить эти проблемы?
Я использовал vscode для создания программы Springboot для подключения к API Finnhub, но она показала следующие ошибки:
\[ОШИБКА\] CompanyServiceTest.testFindAll ? IllegalState Не удалось загрузить ApplicationContext для \[WebMergedContextConfiguration@6c3884f5 testClass = com.hkjava.demo.demofinnhub.CompanyServiceTest, Locations = \[\], классы = \[com.hkjava.demo.demofinnhub.DemoFinnhubApplication\], contextInitializerClasses = \[ \], activeProfiles = \[\], propertySourceLocations = \[\], propertySourceProperties = \["org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true"\], contextCustomizers = \[org.springframework.boot.test , org.springframework.boot.test.web .client.TestRestTemplateContextCustomizer@7fc4780b, org.springframework.boot.test.autoconfigure.actuate.observability.ObservabilityContextCustomizerFactory$DisableObservabilityContextCustomizer@1f, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@0, org. Springframework.boot.test .autoconfigure.web.servlet.WebDriverContextCustomizer@59d4cd39, org.springframework.boot.test.context.SpringBootTestAnnotation@8fbf833d\], resourcesBasePath = "src/main/webapp", contextLoader = org.springframework.boot.test.context.SpringBootContextLoader , родитель = ноль\] \[ОШИБКА\] CompanyServiceTest.testUrl1ByUri ? IllegalState Не удалось загрузить ApplicationContext для \[WebMergedContextConfiguration@6c3884f5 testClass = com.hkjava.demo.demofinnhub.CompanyServiceTest, Locations = \[\], классы = \[com.hkjava.demo.demofinnhub.DemoFinnhubApplication\], contextInitializerClasses = \[ \], activeProfiles = \[\], propertySourceLocations = \[\], propertySourceProperties = \["org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true"\], contextCustomizers = \[org.springframework.boot.test , org.springframework.boot.test.web .client.TestRestTemplateContextCustomizer@7fc4780b, org.springframework.boot.test.autoconfigure.actuate.observability.ObservabilityContextCustomizerFactory$DisableObservabilityContextCustomizer@1f, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@0, org. Springframework.boot.test .autoconfigure.web.servlet.WebDriverContextCustomizer@59d4cd39, org.springframework.boot.test.context.SpringBootTestAnnotation@8fbf833d\], resourcesBasePath = "src/main/webapp", contextLoader = org.springframework.boot.test.context.SpringBootContextLoader , родитель = ноль\] \[ОШИБКА\] DemoFinnhubApplicationTests.contextLoads? IllegalState Не удалось загрузить ApplicationContext для \[WebMergedContextConfiguration@2bd8c8f1 testClass = com.hkjava.demo.demofinnhub.DemoFinnhubApplicationTests, location = \[\], классы = \[com.hkjava.demo.demofinnhub.DemoFinnhubApplication\], contextInitializerClasses = \[ \], activeProfiles = \[\], propertySourceLocations = \[\], propertySourceProperties = \["org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true"\], contextCustomizers = \[org.springframework.boot.test .context.filter.ExcludeFilterContextCustomizer@352ff4da, org.springframework.boot.test.json.DuulateJsonObjectContextCustomizerFactory$DucateJsonObjectContextCustomizer@295cf707, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework .boot.test.web .client.TestRestTemplateContextCustomizer@7fc4780b, org.springframework.boot.test.autoconfigure.actuate.observability.ObservabilityContextCustomizerFactory$DisableObservabilityContextCustomizer@1f, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@0, org. Springframework.boot.test .autoconfigure.web.servlet.WebDriverContextCustomizer@59d4cd39, org.springframework.boot.test.context.SpringBootTestAnnotation@8fbf833d\], resourcesBasePath = "src/main/webapp", contextLoader = org.springframework.boot.test.context.SpringBootContextLoader , родитель = ноль\] Код файла показан ниже:
// CompanyServiceTest импортировать статический org.hamcrest.MatcherAssert.assertThat; импортировать статический org.hamcrest.Matchers.equalTo; импортировать статический org.hamcrest.Matchers.hasItem; импортировать статический org.hamcrest.Matchers.hasProperty; импортировать статический org.hamcrest.Matchers.not; импортировать java.time.LocalDate; импортировать java.util.List; импортировать org.junit.jupiter.api.Test; импортировать org.mockito.Mockito; импортировать org.springframework.beans.factory.annotation.Autowired; импортировать org.springframework.boot.test.context.SpringBootTest; импортировать org.springframework.boot.test.mock.mockito.MockBean; импортировать org.springframework.web.client.RestTemplate; импортировать com.hkjava.demo.demofinnhub.entity.Stock; импортировать com.hkjava.demo.demofinnhub.Exception.FinnhubException; импортировать com.hkjava.demo.demofinnhub.model.CompanyProfile; импортировать com.hkjava.demo.demofinnhub.repository.StockRepository; импортировать com.hkjava.demo.demofinnhub.service.CompanyService; @SpringBootTest общественный класс CompanyServiceTest { @MockBean частный StockRepository StockRepository; @MockBean частный RestTemplate restTemplate; @Autowired частная строка finnhubToken; @Autowired частная компанияСервисная компанияСервис; // Hamcrest, hasItem() -> тестовый массив @Тест недействительный testFindAll() { Stock stock1 = Stock.builder().id(1L).country("США").build(); Stock stock2 = Stock.builder().id(2L).country("CN").build(); Mockito.when(stockRepository.findAll()).thenReturn(List.of(stock1, stock2)); List stocks = CompanyService.findAll(); // вызов stockRepository.findAll() AssertThat(акции, hasItem(hasProperty("страна", равныйTo("CN")))); AssertThat(stocks, hasItem(hasProperty("country", равныйTo("США")))); AssertThat(акции, not(hasItem(hasProperty("country", равныйTo("HK"))))); } @Тест void testUrl1ByUri() выдает FinnhubException { Ожидаемая строкаUrl = "https://finnhub.io/api/v1/stock/profile ... APL&token=" .concat(finnhubToken); CompanyProfile издеваетсяCompanyProfile = CompanyProfile.builder() // .country("США") // .ipoDate(LocalDate.of(1988, 12, 31)) // .строить(); Mockito.when(restTemplate.getForObject(expectedUrl, CompanyProfile.class)) .thenReturn(mockedCompanyProfile); Профиль компании = CompanyService.getCompanyProfile("AAPL"); // вызов stockRepository.findAll() AssertThat(profile, hasProperty("страна", равныйTo("США"))); } } // DemoFinnhubApplicationTests импортировать org.junit.jupiter.api.Test; импортировать org.springframework.boot.test.context.SpringBootTest; @SpringBootTest класс DemoFinnhubApplicationTests { @Тест недействительный contextLoads () { } } Как я могу решить эти проблемы?
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение