JPA双方向関連付けのテスト
17276 ワード
JPA双方向関連関係マッピングとテストコード作成中に発生した困難な旅.
failed to replace datasource with an embedded database for tests
->実際のデータベースが接続されていないため
luvshort schemaに接続して、すでにビデオテーブルがあると言っていたので、テーブルのないnew schemaに接続して、結局また...
-> application.ymlを設定するのを忘れました...jpa:hibernate:ddl-auto:updateに設定!
not-null property references a null or transient value
->エンティティの保存時に埋め込みタイプを初期化しない場合に発生します.
双方向マッピングテストコードはパスしましたが、実際のDBでは保存できません.場所が埋まっていないからですか?
テストコードの方面の知識は特に不足して、毎回間違いが現れる時、グーグルで知識を勉強して理解するのはとても面白いです、ほほほ、しかしいつも私をつかんでテストの方法を書くことを学びます
テストコードはパスしましたが、このエラーが発生しました.
テストに合格するって言ったでしょ、ログって何?
こんな文が出てきました.
testディレクトリにも適用されます.ymlを記入する必要があるようです
従来の
ビデオエンティティを作成すると、user idxも一緒に格納されていることがわかります.
シャベル。
failed to replace datasource with an embedded database for tests
->実際のデータベースが接続されていないため
畑を鋤く。
luvshort schemaに接続して、すでにビデオテーブルがあると言っていたので、テーブルのないnew schemaに接続して、結局また...
-> application.ymlを設定するのを忘れました...jpa:hibernate:ddl-auto:updateに設定!
畑を鋤く。
not-null property references a null or transient value
->エンティティの保存時に埋め込みタイプを初期化しない場合に発生します.
土を掻く。
双方向マッピングテストコードはパスしましたが、実際のDBでは保存できません.場所が埋まっていないからですか?
テストコードの方面の知識は特に不足して、毎回間違いが現れる時、グーグルで知識を勉強して理解するのはとても面白いです、ほほほ、しかしいつも私をつかんでテストの方法を書くことを学びます
畑を鋤く。
テストコードはパスしましたが、このエラーが発生しました.
23:13:06.331 [main] DEBUG org.springframework.test.context.junit4.SpringJUnit4ClassRunner - SpringJUnit4ClassRunner constructor called with [class com.example.backend.domain.JpaTestApplicationTests]
23:13:06.362 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating CacheAwareContextLoaderDelegate from class [org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate]
23:13:06.398 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating BootstrapContext using constructor [public org.springframework.test.context.support.DefaultBootstrapContext(java.lang.Class,org.springframework.test.context.CacheAwareContextLoaderDelegate)]
23:13:06.574 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating TestContextBootstrapper for![](https://velog.velcdn.com/images/savannah030/post/395fe824-e716-4f88-ad9e-4425111da884/image.jpg)
test class [com.example.backend.domain.JpaTestApplicationTests] from class [org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTestContextBootstrapper]
23:13:06.627 [main] INFO org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTestContextBootstrapper - Neither @ContextConfiguration nor @ContextHierarchy found for test class [com.example.backend.domain.JpaTestApplicationTests], using SpringBootContextLoader
23:13:06.641 [main] DEBUG org.springframework.test.context.support.AbstractContextLoader - Did not detect default resource location for test class [com.example.backend.domain.JpaTestApplicationTests]: class path resource [com/example/backend/domain/JpaTestApplicationTests-context.xml] does not exist
23:13:06.642 [main] DEBUG org.springframework.test.context.support.AbstractContextLoader - Did not detect default resource location for test class [com.example.backend.domain.JpaTestApplicationTests]: class path resource [com/example/backend/domain/JpaTestApplicationTestsContext.groovy] does not exist
23:13:06.643 [main] INFO org.springframework.test.context.support.AbstractContextLoader - Could not detect default resource locations for test class [com.example.backend.domain.JpaTestApplicationTests]: no resource found for suffixes {-context.xml, Context.groovy}.
23:13:06.645 [main] INFO org.springframework.test.context.support.AnnotationConfigContextLoaderUtils - Could not detect default configuration classes for test class [com.example.backend.domain.JpaTestApplicationTests]: JpaTestApplicationTests does not declare any static, non-private, non-final, nested classes annotated with @Configuration.
23:13:06.880 [main] DEBUG org.springframework.test.context.support.ActiveProfilesUtils - Could not find an 'annotation declaring class' for annotation type [org.springframework.test.context.ActiveProfiles] and class [com.example.backend.domain.JpaTestApplicationTests]
23:13:07.153 [main] DEBUG org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider - Identified candidate component class: file [C:\Users\yjkim\Desktop\syhan\Spring\luvShort\backend\build\classes\java\main\com\example\backend\BackendApplication.class]
23:13:07.156 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Found @SpringBootConfiguration com.example.backend.BackendApplication for test class com.example.backend.domain.JpaTestApplicationTests
23:13:07.165 [main] DEBUG org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTestContextBootstrapper - @TestExecutionListeners is not present for class [com.example.backend.domain.JpaTestApplicationTests]: using defaults.
23:13:07.167 [main] INFO org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTestContextBootstrapper - Loaded default TestExecutionListener class names from location [META-INF/spring.factories]: [org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener, org.springframework.boot.test.autoconfigure.webservices.client.MockWebServiceServerTestExecutionListener, org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener, org.springframework.test.context.web.ServletTestExecutionListener, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener, org.springframework.test.context.event.ApplicationEventsTestExecutionListener, org.springframework.test.context.support.DependencyInjectionTestExecutionListener, org.springframework.test.context.support.DirtiesContextTestExecutionListener, org.springframework.test.context.transaction.TransactionalTestExecutionListener, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener, org.springframework.test.context.event.EventPublishingTestExecutionListener]
23:13:07.230 [main] INFO org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTestContextBootstrapper - Using TestExecutionListeners: [org.springframework.test.context.web.ServletTestExecutionListener@31368b99, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener@1725dc0f, org.springframework.test.context.event.ApplicationEventsTestExecutionListener@3911c2a7, org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener@4ac3c60d, org.springframework.boot.test.autoconfigure.SpringBootDependencyInjectionTestExecutionListener@4facf68f, org.springframework.test.context.support.DirtiesContextTestExecutionListener@76508ed1, org.springframework.test.context.transaction.TransactionalTestExecutionListener@41e36e46, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener@15c43bd9, org.springframework.test.context.event.EventPublishingTestExecutionListener@3d74bf60, org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener@4f209819, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener@15eb5ee5, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener@2145b572, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener@39529185, org.springframework.boot.test.autoconfigure.webservices.client.MockWebServiceServerTestExecutionListener@72f926e6, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener@3daa422a]
23:13:07.234 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved @ProfileValueSourceConfiguration [null] for test class [com.example.backend.domain.JpaTestApplicationTests]
23:13:07.236 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [com.example.backend.domain.JpaTestApplicationTests]
23:13:07.238 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved @ProfileValueSourceConfiguration [null] for test class [com.example.backend.domain.JpaTestApplicationTests]
23:13:07.238 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [com.example.backend.domain.JpaTestApplicationTests]
23:13:07.239 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved @ProfileValueSourceConfiguration [null] for test class [com.example.backend.domain.JpaTestApplicationTests]
23:13:07.239 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [com.example.backend.domain.JpaTestApplicationTests]
23:13:07.259 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved @ProfileValueSourceConfiguration [null] for test class [com.example.backend.domain.JpaTestApplicationTests]
23:13:07.259 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [com.example.backend.domain.JpaTestApplicationTests]
23:13:07.262 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved @ProfileValueSourceConfiguration [null] for test class [com.example.backend.domain.JpaTestApplicationTests]
23:13:07.262 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [com.example.backend.domain.JpaTestApplicationTests]
23:13:07.264 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved @ProfileValueSourceConfiguration [null] for test class [com.example.backend.domain.JpaTestApplicationTests]
23:13:07.264 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [com.example.backend.domain.JpaTestApplicationTests]
23:13:07.280 [main] DEBUG org.springframework.test.context.support.AbstractDirtiesContextTestExecutionListener - Before test class: context [DefaultTestContext@15ff3e9e testClass = JpaTestApplicationTests, testInstance = [null], testMethod = [null], testException = [null], mergedContextConfiguration = [MergedContextConfiguration@5fdcaa40 testClass = JpaTestApplicationTests, locations = '{}', classes = '{class com.example.backend.BackendApplication}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTestContextBootstrapper=true}', contextCustomizers = set[org.springframework.boot.test.autoconfigure.OverrideAutoConfigurationContextCustomizerFactory$DisableAutoConfigurationContextCustomizer@140e5a13, org.springframework.boot.test.autoconfigure.actuate.metrics.MetricsExportContextCustomizerFactory$DisableMetricExportContextCustomizer@6c9f5c0d, org.springframework.boot.test.autoconfigure.filter.TypeExcludeFiltersContextCustomizer@351584c0, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@7abc32d5, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizerFactory$Customizer@4e41089d, [ImportsContextCustomizer@6dc17b83 key = [org.springframework.boot.autoconfigure.cache.CacheAutoConfiguration, org.springframework.boot.autoconfigure.data.jpa.JpaRepositoriesAutoConfiguration, org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration, org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration, org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration, org.springframework.boot.autoconfigure.jdbc.JdbcTemplateAutoConfiguration, org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration, org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration, org.springframework.boot.autoconfigure.sql.init.SqlInitializationAutoConfiguration, org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration, org.springframework.boot.test.autoconfigure.jdbc.TestDatabaseAutoConfiguration, org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManagerAutoConfiguration]], org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@6b1274d2, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@ba8d91c, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.context.SpringBootTestArgs@1, org.springframework.boot.test.context.SpringBootTestWebEnvironment@0], contextLoader = 'org.springframework.boot.test.context.SpringBootContextLoader', parent = [null]], attributes = map[[empty]]], class annotated with @DirtiesContext [false] with mode [null].
23:13:07.286 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved @ProfileValueSourceConfiguration [null] for test class [com.example.backend.domain.JpaTestApplicationTests]
23:13:07.286 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [com.example.backend.domain.JpaTestApplicationTests]
23:13:07.299 [main] DEBUG org.springframework.test.context.support.DependencyInjectionTestExecutionListener - Performing dependency injection for test context [[DefaultTestContext@15ff3e9e testClass = JpaTestApplicationTests, testInstance = com.example.backend.domain.JpaTestApplicationTests@67d48005, testMethod = [null], testException = [null], mergedContextConfiguration = [MergedContextConfiguration@5fdcaa40 testClass = JpaTestApplicationTests, locations = '{}', classes = '{class com.example.backend.BackendApplication}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTestContextBootstrapper=true}', contextCustomizers = set[org.springframework.boot.test.autoconfigure.OverrideAutoConfigurationContextCustomizerFactory$DisableAutoConfigurationContextCustomizer@140e5a13, org.springframework.boot.test.autoconfigure.actuate.metrics.MetricsExportContextCustomizerFactory$DisableMetricExportContextCustomizer@6c9f5c0d, org.springframework.boot.test.autoconfigure.filter.TypeExcludeFiltersContextCustomizer@351584c0, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@7abc32d5, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizerFactory$Customizer@4e41089d, [ImportsContextCustomizer@6dc17b83 key = [org.springframework.boot.autoconfigure.cache.CacheAutoConfiguration, org.springframework.boot.autoconfigure.data.jpa.JpaRepositoriesAutoConfiguration, org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration, org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration, org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration, org.springframework.boot.autoconfigure.jdbc.JdbcTemplateAutoConfiguration, org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration, org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration, org.springframework.boot.autoconfigure.sql.init.SqlInitializationAutoConfiguration, org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration, org.springframework.boot.test.autoconfigure.jdbc.TestDatabaseAutoConfiguration, org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManagerAutoConfiguration]], org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@6b1274d2, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@ba8d91c, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.context.SpringBootTestArgs@1, org.springframework.boot.test.context.SpringBootTestWebEnvironment@0], contextLoader = 'org.springframework.boot.test.context.SpringBootContextLoader', parent = [null]], attributes = map['org.springframework.test.context.event.ApplicationEventsTestExecutionListener.recordApplicationEvents' -> false]]].
何か間違ってるみたいだけど眠い…寝て明日起きてから見ます.テストに合格するって言ったでしょ、ログって何?
閉まってまた開く。
こんな文が出てきました.
解決する。
testディレクトリにも適用されます.ymlを記入する必要があるようです
解決する。
従来の
BackendApplicationTests.java
を削除し、JpaTestApplicationTests.java
に@SpringBootTest
を貼り付けた.DBが反映されているか
ビデオエンティティを作成すると、user idxも一緒に格納されていることがわかります.
Reference
この問題について(JPA双方向関連付けのテスト), 我々は、より多くの情報をここで見つけました https://velog.io/@savannah030/테스트-코드-작성テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol