Search
Duplicate

회원가입 테스트코드 작성

Tags
테스트
Date
2023/05/11
Tags 2
Junit Test
URL
비고
아래 내용으로 변경
사람
Junit Test Code 작성
회원가입/로그인과 관련된 기능을 만들었는데 제대로 작동하는지 알아보기 위해 Mapper 단위의 테스트를 진행해 보았습니다.
폴더트리
User
mybatis
test
UserMapper
여기서 회원가입 기능에 대해 JunitTest 를 진행하였습니다.
UserTest
현재는 회원가입에 관한 내용만 있지만, 회원에 관한 다른 테스트 내용이 추가될 수 있어서 이름을 UserTest 라 지었습니다.
이런식으로 회원을 생성해주었고, 기본으로 테스트 수행 후 롤백이 되는데 이를 막기위해 @Rollback(false) 어노테이션을 달아주었습니다.
결과
[콘솔]
2023-05-11 19:45:47.370 INFO 100900 --- [ main] com.team.project2.UserTest : Starting UserTest using Java 11.0.17 on sieun with PID 100900 (started by sieun in C:\GitHub\StudyGroupTeamProject) 2023-05-11 19:45:47.371 INFO 100900 --- [ main] com.team.project2.UserTest : No active profile set, falling back to 1 default profile: "default" 2023-05-11 19:45:48.310 INFO 100900 --- [ main] com.team.project2.UserTest : Started UserTest in 1.352 seconds (JVM running for 2.378) 2023-05-11 19:45:48.331 INFO 100900 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting... 2023-05-11 19:45:48.494 INFO 100900 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed. 2023-05-11 19:45:48.500 INFO 100900 --- [ main] o.s.t.c.transaction.TransactionContext : Began transaction (1) for test context [DefaultTestContext@3549bca9 testClass = UserTest, testInstance = com.team.project2.UserTest@7502291e, testMethod = signUpTest@UserTest, testException = [null], mergedContextConfiguration = [MergedContextConfiguration@4f25b795 testClass = UserTest, locations = '{}', classes = '{class com.team.project2.StudyManagerApplication}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{org.mybatis.spring.boot.test.autoconfigure.MybatisTestContextBootstrapper=true}', contextCustomizers = set[[ImportsContextCustomizer@6fb365ed key = [org.springframework.boot.autoconfigure.cache.CacheAutoConfiguration, 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.transaction.TransactionAutoConfiguration, org.springframework.boot.autoconfigure.sql.init.SqlInitializationAutoConfiguration, org.mybatis.spring.boot.autoconfigure.MybatisLanguageDriverAutoConfiguration, org.mybatis.spring.boot.autoconfigure.MybatisAutoConfiguration, org.springframework.boot.test.autoconfigure.jdbc.TestDatabaseAutoConfiguration]], org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@3e2059ae, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@275bf9b3, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.autoconfigure.OverrideAutoConfigurationContextCustomizerFactory$DisableAutoConfigurationContextCustomizer@27adc16e, org.springframework.boot.test.autoconfigure.actuate.metrics.MetricsExportContextCustomizerFactory$DisableMetricExportContextCustomizer@4066c471, org.springframework.boot.test.autoconfigure.filter.TypeExcludeFiltersContextCustomizer@351584c0, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@b936ff4, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizerFactory$Customizer@4eaf3684, 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]]; transaction manager [org.springframework.jdbc.support.JdbcTransactionManager@de81be1]; rollback [false] 회원가입이 완료되었습니다. 2023-05-11 19:45:48.912 INFO 100900 --- [ main] o.s.t.c.transaction.TransactionContext : Committed transaction for test: [DefaultTestContext@3549bca9 testClass = UserTest, testInstance = com.team.project2.UserTest@7502291e, testMethod = signUpTest@UserTest, testException = [null], mergedContextConfiguration = [MergedContextConfiguration@4f25b795 testClass = UserTest, locations = '{}', classes = '{class com.team.project2.StudyManagerApplication}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{org.mybatis.spring.boot.test.autoconfigure.MybatisTestContextBootstrapper=true}', contextCustomizers = set[[ImportsContextCustomizer@6fb365ed key = [org.springframework.boot.autoconfigure.cache.CacheAutoConfiguration, 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.transaction.TransactionAutoConfiguration, org.springframework.boot.autoconfigure.sql.init.SqlInitializationAutoConfiguration, org.mybatis.spring.boot.autoconfigure.MybatisLanguageDriverAutoConfiguration, org.mybatis.spring.boot.autoconfigure.MybatisAutoConfiguration, org.springframework.boot.test.autoconfigure.jdbc.TestDatabaseAutoConfiguration]], org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@3e2059ae, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@275bf9b3, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.autoconfigure.OverrideAutoConfigurationContextCustomizerFactory$DisableAutoConfigurationContextCustomizer@27adc16e, org.springframework.boot.test.autoconfigure.actuate.metrics.MetricsExportContextCustomizerFactory$DisableMetricExportContextCustomizer@4066c471, org.springframework.boot.test.autoconfigure.filter.TypeExcludeFiltersContextCustomizer@351584c0, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@b936ff4, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizerFactory$Customizer@4eaf3684, 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]] 2023-05-11 19:45:48.926 INFO 100900 --- [ionShutdownHook] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown initiated... 2023-05-11 19:45:48.937 INFO 100900 --- [ionShutdownHook] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown completed.
Java
복사
[DB]
값이 잘 들어온걸 확인할 수 있습니다.
주의사항
인텔리제이에 연결했을때는 새로고침하면 바로 값이 들어가있는것을 확인할 수 있지만, mySql 에서는 commit; 을 하고 새로고침해야 값이 들어가있는것을 확인할 수 있었습니다.