cyh60993013
@cyh60993013
Reviews Written
-
Average Rating
-
Posts
Q&A
JUnit5์์ @Autowired์ฌ์ฉ ์ด์
์ปจํ ์ด๋๊ฐ 2๊ฐ ์์ฑ๋ ์ค์ ์๊ฐ ๋ชปํ๋๋ฐ, ๋ต๋ณ ๊ฐ์ฌํฉ๋๋ค!!
- 0
- 4
- 723
Q&A
JUnit5์์ @Autowired์ฌ์ฉ ์ด์
๋๋ผ์ด๋ธ ๋งํฌ์ ๋๋ค. https://drive.google.com/file/d/1yZm0825uOExt2y540G6kuO3HNJtjuB1Z/view?usp=sharing ์คํ ๋ฐฉ๋ฒ์ 21~25์ค์ ์ฝ๋๋ฅผ ์ด์ฉํด test๋๋ ํ ๋ฆฌ์ service/MemberServiceTest์ ํ์๊ฐ์ ๋จ์ํ ์คํธ๋ฅผ ์คํํ๋ฉด ํ ์คํธ๊ฐ ์ ์์ ์ผ๋ก ์คํ๋๊ณ , 21~25๋ฅผ ์ฃผ์์ฒ๋ฆฌ ํ๊ณ 27~29์ค์ ์ด์ฉํด ํ ์คํธ๋ฅผ ์คํํ๋ฉด ํ ์คํธ์ ์คํจํฉ๋๋ค. ๊ถ๊ธํ ์ spring๊ฐ์๋ฅผ ๋ค์ ๋ AnnotationConfigApplicationContext๋ฅผ ์ด์ฉํด bean์ ๊ฐ์ ธ์ ํ ์คํธ๋ฅผ ์งํํ์ ์ ์ ๊ฐ ์์๋ก @Autowired๊ฐ ์๋ AnnotationConfigApplicationContext๋ฅผ ์ด์ฉํด bean์ ๊ฐ์ ธ์ ์งํํด๋ดค๋๋ฐ ํ ์คํธ์ ์คํจํ์ต๋๋ค. AnnotationConfigApplicationContext์ @Autowired์ ์ฐจ์ด์ ์ ๊ตฌ๊ธ๋งํด ์ฐพ์๋ดค์ง๋ง ์ ์ดํด๊ฐ ๊ฐ์ง์์ ์ง๋ฌธ ๋จ๊น๋๋ค. ์๋๋ ํ์๊ฐ์ ํ ์คํธ ์คํจ ๋๋ฒ๊น ์ฝ๋ ์ ์ฒด์ ๋๋ค. 2022-08-07 17:30:06.419 INFO 4131 --- [ main] o.s.t.c.transaction.TransactionContext : Began transaction (1) for test context [DefaultTestContext@5f7b97da testClass = MemberServiceTest, testInstance = japbook.jpashop.service.MemberServiceTest@48463900, testMethod = ํ์๊ฐ์ @MemberServiceTest, testException = [null], mergedContextConfiguration = [WebMergedContextConfiguration@18b0930f testClass = MemberServiceTest, locations = '{}', classes = '{class japbook.jpashop.JpashopApplication}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true}', contextCustomizers = set[org.springframework.boot.test.autoconfigure.actuate.metrics.MetricsExportContextCustomizerFactory$DisableMetricExportContextCustomizer@5852c06f, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@0, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizerFactory$Customizer@1169afe1, org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@13df2a8c, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@1787f2a0, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.web.client.TestRestTemplateContextCustomizer@dc9876b, org.springframework.boot.test.context.SpringBootTestArgs@1, org.springframework.boot.test.context.SpringBootTestWebEnvironment@11e21d0e], resourceBasePath = 'src/main/webapp', contextLoader = 'org.springframework.boot.test.context.SpringBootContextLoader', parent = [null]], attributes = map['org.springframework.test.context.web.ServletTestExecutionListener.activateListener' -> true, 'org.springframework.test.context.web.ServletTestExecutionListener.populatedRequestContextHolder' -> true, 'org.springframework.test.context.web.ServletTestExecutionListener.resetRequestContextHolder' -> true, 'org.springframework.test.context.event.ApplicationEventsTestExecutionListener.recordApplicationEvents' -> false]]; transaction manager [org.springframework.orm.jpa.JpaTransactionManager@6abbdcde]; rollback [true] 2022-08-07 17:30:06.679 DEBUG 4131 --- [ main] org.hibernate.SQL : select member0_.member_id as member_i1_4_, member0_.city as city2_4_, member0_.street as street3_4_, member0_.zipcode as zipcode4_4_, member0_.name as name5_4_ from member member0_ where member0_.name=? 2022-08-07 17:30:06.687 TRACE 4131 --- [ main] o.h.type.descriptor.sql.BasicBinder : binding parameter [1] as [VARCHAR] - [Cha1] 2022-08-07 17:30:06.695 INFO 4131 --- [ main] p6spy : #1659861006695 | took 6ms | statement | connection 8| url jdbc:h2:mem:bf903789-32b0-4e7c-a39d-964b893862ee select member0_.member_id as member_i1_4_, member0_.city as city2_4_, member0_.street as street3_4_, member0_.zipcode as zipcode4_4_, member0_.name as name5_4_ from member member0_ where member0_.name=? select member0_.member_id as member_i1_4_, member0_.city as city2_4_, member0_.street as street3_4_, member0_.zipcode as zipcode4_4_, member0_.name as name5_4_ from member member0_ where member0_.name='Cha1'; 2022-08-07 17:30:06.702 DEBUG 4131 --- [ main] org.hibernate.SQL : call next value for hibernate_sequence 2022-08-07 17:30:06.703 INFO 4131 --- [ main] p6spy : #1659861006703 | took 0ms | statement | connection 8| url jdbc:h2:mem:bf903789-32b0-4e7c-a39d-964b893862ee call next value for hibernate_sequence call next value for hibernate_sequence; 2022-08-07 17:30:06.758 DEBUG 4131 --- [ main] org.hibernate.SQL : insert into member (city, street, zipcode, name, member_id) values (?, ?, ?, ?, ?) 2022-08-07 17:30:06.759 TRACE 4131 --- [ main] o.h.type.descriptor.sql.BasicBinder : binding parameter [1] as [VARCHAR] - [null] 2022-08-07 17:30:06.759 TRACE 4131 --- [ main] o.h.type.descriptor.sql.BasicBinder : binding parameter [2] as [VARCHAR] - [null] 2022-08-07 17:30:06.759 TRACE 4131 --- [ main] o.h.type.descriptor.sql.BasicBinder : binding parameter [3] as [VARCHAR] - [null] 2022-08-07 17:30:06.759 TRACE 4131 --- [ main] o.h.type.descriptor.sql.BasicBinder : binding parameter [4] as [VARCHAR] - [Cha1] 2022-08-07 17:30:06.760 TRACE 4131 --- [ main] o.h.type.descriptor.sql.BasicBinder : binding parameter [5] as [BIGINT] - [1] 2022-08-07 17:30:06.761 INFO 4131 --- [ main] p6spy : #1659861006761 | took 0ms | statement | connection 8| url jdbc:h2:mem:bf903789-32b0-4e7c-a39d-964b893862ee insert into member (city, street, zipcode, name, member_id) values (?, ?, ?, ?, ?) insert into member (city, street, zipcode, name, member_id) values (NULL, NULL, NULL, 'Cha1', 1); 2022-08-07 17:30:06.765 INFO 4131 --- [ main] p6spy : #1659861006765 | took 0ms | commit | connection 8| url jdbc:h2:mem:bf903789-32b0-4e7c-a39d-964b893862ee ; 2022-08-07 17:30:06.868 DEBUG 4131 --- [ main] org.hibernate.SQL : select member0_.member_id as member_i1_4_0_, member0_.city as city2_4_0_, member0_.street as street3_4_0_, member0_.zipcode as zipcode4_4_0_, member0_.name as name5_4_0_ from member member0_ where member0_.member_id=? 2022-08-07 17:30:06.869 TRACE 4131 --- [ main] o.h.type.descriptor.sql.BasicBinder : binding parameter [1] as [BIGINT] - [1] 2022-08-07 17:30:06.870 INFO 4131 --- [ main] p6spy : #1659861006870 | took 0ms | statement | connection 9| url jdbc:h2:mem:bf903789-32b0-4e7c-a39d-964b893862ee select member0_.member_id as member_i1_4_0_, member0_.city as city2_4_0_, member0_.street as street3_4_0_, member0_.zipcode as zipcode4_4_0_, member0_.name as name5_4_0_ from member member0_ where member0_.member_id=? select member0_.member_id as member_i1_4_0_, member0_.city as city2_4_0_, member0_.street as street3_4_0_, member0_.zipcode as zipcode4_4_0_, member0_.name as name5_4_0_ from member member0_ where member0_.member_id=1; 2022-08-07 17:30:06.874 TRACE 4131 --- [ main] o.h.type.descriptor.sql.BasicExtractor : extracted value ([city2_4_0_] : [VARCHAR]) - [null] 2022-08-07 17:30:06.874 TRACE 4131 --- [ main] o.h.type.descriptor.sql.BasicExtractor : extracted value ([street3_4_0_] : [VARCHAR]) - [null] 2022-08-07 17:30:06.874 TRACE 4131 --- [ main] o.h.type.descriptor.sql.BasicExtractor : extracted value ([zipcode4_4_0_] : [VARCHAR]) - [null] 2022-08-07 17:30:06.874 TRACE 4131 --- [ main] o.h.type.descriptor.sql.BasicExtractor : extracted value ([name5_4_0_] : [VARCHAR]) - [Cha1] 2022-08-07 17:30:06.878 TRACE 4131 --- [ main] org.hibernate.type.CollectionType : Created collection wrapper: [japbook.jpashop.domain.Member.orders#1] 2022-08-07 17:30:06.896 INFO 4131 --- [ main] p6spy : #1659861006896 | took 0ms | rollback | connection 7| url jdbc:h2:mem:test ; 2022-08-07 17:30:06.897 INFO 4131 --- [ main] o.s.t.c.transaction.TransactionContext : Rolled back transaction for test: [DefaultTestContext@5f7b97da testClass = MemberServiceTest, testInstance = japbook.jpashop.service.MemberServiceTest@48463900, testMethod = ํ์๊ฐ์ @MemberServiceTest, testException = org.opentest4j.AssertionFailedError: expected: japbook.jpashop.domain.Member@1d47b761 but was: japbook.jpashop.domain.Member@7053b64b, mergedContextConfiguration = [WebMergedContextConfiguration@18b0930f testClass = MemberServiceTest, locations = '{}', classes = '{class japbook.jpashop.JpashopApplication}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true}', contextCustomizers = set[org.springframework.boot.test.autoconfigure.actuate.metrics.MetricsExportContextCustomizerFactory$DisableMetricExportContextCustomizer@5852c06f, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@0, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizerFactory$Customizer@1169afe1, org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@13df2a8c, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@1787f2a0, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.web.client.TestRestTemplateContextCustomizer@dc9876b, org.springframework.boot.test.context.SpringBootTestArgs@1, org.springframework.boot.test.context.SpringBootTestWebEnvironment@11e21d0e], resourceBasePath = 'src/main/webapp', contextLoader = 'org.springframework.boot.test.context.SpringBootContextLoader', parent = [null]], attributes = map['org.springframework.test.context.web.ServletTestExecutionListener.activateListener' -> true, 'org.springframework.test.context.web.ServletTestExecutionListener.populatedRequestContextHolder' -> true, 'org.springframework.test.context.web.ServletTestExecutionListener.resetRequestContextHolder' -> true, 'org.springframework.test.context.event.ApplicationEventsTestExecutionListener.recordApplicationEvents' -> false]] org.opentest4j.AssertionFailedError: expected: japbook.jpashop.domain.Member@1d47b761 but was: japbook.jpashop.domain.Member@7053b64b Expected :japbook.jpashop.domain.Member@1d47b761 Actual :japbook.jpashop.domain.Member@7053b64b at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at japbook.jpashop.service.MemberServiceTest.ํ์๊ฐ์ (MemberServiceTest.java:41) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:566) at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:725) at org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60) at org.junit.jupiter.engine.execution.InvocationInterceptorChain$ValidatingInvocation.proceed(InvocationInterceptorChain.java:131) at org.junit.jupiter.engine.extension.TimeoutExtension.intercept(TimeoutExtension.java:149) at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestableMethod(TimeoutExtension.java:140) at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestMethod(TimeoutExtension.java:84) at org.junit.jupiter.engine.execution.ExecutableInvoker$ReflectiveInterceptorCall.lambda$ofVoidMethod$0(ExecutableInvoker.java:115) at org.junit.jupiter.engine.execution.ExecutableInvoker.lambda$invoke$0(ExecutableInvoker.java:105) at org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:106) at org.junit.jupiter.engine.execution.InvocationInterceptorChain.proceed(InvocationInterceptorChain.java:64) at org.junit.jupiter.engine.execution.InvocationInterceptorChain.chainAndInvoke(InvocationInterceptorChain.java:45) at org.junit.jupiter.engine.execution.InvocationInterceptorChain.invoke(InvocationInterceptorChain.java:37) at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:104) at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:98) at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$7(TestMethodTestDescriptor.java:214) at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(TestMethodTestDescriptor.java:210) at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:135) at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:66) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:151) at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141) at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139) at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138) at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95) at java.base/java.util.ArrayList.forEach(ArrayList.java:1541) at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155) at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141) at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139) at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138) at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95) at java.base/java.util.ArrayList.forEach(ArrayList.java:1541) at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155) at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141) at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139) at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138) at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95) at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:35) at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57) at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:54) at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:107) at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:88) at org.junit.platform.launcher.core.EngineExecutionOrchestrator.lambda$execute$0(EngineExecutionOrchestrator.java:54) at org.junit.platform.launcher.core.EngineExecutionOrchestrator.withInterceptedStreams(EngineExecutionOrchestrator.java:67) at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:52) at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:114) at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:86) at org.junit.platform.launcher.core.DefaultLauncherSession$DelegatingLauncher.execute(DefaultLauncherSession.java:86) at org.junit.platform.launcher.core.SessionPerRequestLauncher.execute(SessionPerRequestLauncher.java:53) at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:71) at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33) at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:220) at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:53) ์ข์ ๊ฐ์ ์ ๊ณตํด์ฃผ์ ์ ์ ๋ง ๊ฐ์ฌํฉ๋๋ค!!
- 0
- 4
- 723




