๊ฐœ๋ฐœ์ž HOON
๐Ÿ› HOON DEVLog
๊ฐœ๋ฐœ์ž HOON
์ „์ฒด ๋ฐฉ๋ฌธ์ž
์˜ค๋Š˜
์–ด์ œ
  • ๐Ÿ˜Ž ์ „์ฒด ์นดํ…Œ๊ณ ๋ฆฌ (137)
    • ๐Ÿ“ ์‹ ์ž… ์ธํ„ฐ๋ทฐ ์ค€๋น„ (7)
    • ๐Ÿฆ” ์ทจ์—…์ค€๋น„ ๊ธฐ๋ก (7)
    • โ˜• ์ž๋ฐ” : JAVA (5)
    • ๐Ÿ ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ๋Œ€๋น„ : PS (80)
    • ๐ŸŒฑ ๋ฐฑ์—”๋“œ : Backend (13)
    • ๐Ÿงช ์ปดํ“จํ„ฐ๊ณผํ•™ : CS (11)
    • ๐Ÿ—‚ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค : DB (1)
    • ๐Ÿƒ‍โ™‚๏ธ DEVLOG (8)
    • โš™๏ธ Trouble Shooting (5)

๋ธ”๋กœ๊ทธ ๋ฉ”๋‰ด

  • ํ™ˆ
  • GitHub
  • Resume

๊ณต์ง€์‚ฌํ•ญ

์ธ๊ธฐ ๊ธ€

์ตœ๊ทผ ๊ธ€

ํ‹ฐ์Šคํ† ๋ฆฌ

hELLO ยท Designed By ์ •์ƒ์šฐ.
๊ฐœ๋ฐœ์ž HOON

๐Ÿ› HOON DEVLog

[DEVLOG] JUnit5๋ฅผ ํ™œ์šฉํ•œ ํ…Œ์ŠคํŠธ ์ฝ”๋“œ ์ž‘์„ฑ๊ณผ @DataJpaTest ์‚ฌ์šฉ์‹œ ๋ฐœ์ƒํ•œ ๋ฌธ์ œ ํ•ด๊ฒฐ
๐Ÿƒ‍โ™‚๏ธ DEVLOG

[DEVLOG] JUnit5๋ฅผ ํ™œ์šฉํ•œ ํ…Œ์ŠคํŠธ ์ฝ”๋“œ ์ž‘์„ฑ๊ณผ @DataJpaTest ์‚ฌ์šฉ์‹œ ๋ฐœ์ƒํ•œ ๋ฌธ์ œ ํ•ด๊ฒฐ

2023. 4. 12. 21:24

 

๐Ÿค” Spring Data JPA๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด์„œ JPA ๊ด€๋ จ ํ…Œ์ŠคํŠธ๋งŒ ์ง„ํ–‰ํ•˜๊ณ  ์‹ถ์„ ๋•Œ

 

๋ชจ๋“  ๋นˆ์„ ๋“ฑ๋กํ•˜๋Š” @SpringBootTest ์–ด๋…ธํ…Œ์ด์…˜์„ ์‚ฌ์šฉํ•˜๋ฉด ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ ๊ทœ๋ชจ๊ฐ€ ์ปค์งˆ ์ˆ˜๋ก ์†๋„๊ฐ€ ๋А๋ ค์ง‘๋‹ˆ๋‹ค.

ํ•˜์ง€๋งŒ, JPA ๊ด€๋ จ ํ…Œ์ŠคํŠธ๋งŒ ์ง„ํ–‰ํ•˜๊ณ  ์‹ถ์€ ๊ฒฝ์šฐ๊ฐ€ ๋ถ„๋ช…ํ•˜๊ฒŒ ์กด์žฌํ•ฉ๋‹ˆ๋‹ค.

์ด์™€ ๊ฐ™์€ ๊ฒฝ์šฐ์—๋Š”, @DataJpaTest ์–ด๋…ธํ…Œ์ด์…˜์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

 

@DataJpaTest
class GTMemberEntityTest{

    @Autowired
    private GTAccountInfoRepository accountInfoRepository;

    @Autowired
    private GTMemberInfoRepository memberInfoRepository;

    @Autowired
    private GTAccountUserRoleInfoRepository accountUserRoleInfoRepository;

    @Test
    @DisplayName("๐Ÿค” 1. ๊ณ„์ •์ •๋ณด ์ƒ์„ฑ ๋ฐ ์ €์žฅ ํ…Œ์ŠคํŠธ : ์„ฑ๊ณต ์ผ€์ด์Šค")
    @Transactional
    public void testForCreateNewAccountInfoAndSave(){
        GTAccountInfo mockAccountInfo = GTAccountInfo.builder()
                .accountEmail("test@example.com")
                .accountPW("1234")
                .build();

        GTAccountInfo savedAccountInfo = accountInfoRepository.save(mockAccountInfo);

        assertEquals(savedAccountInfo.getAccountEmail(), "test@example.com");
        assertEquals(savedAccountInfo.getAccountPW(), "1234");
        assertEquals(savedAccountInfo.getRoles().size(), 0);

    }
    
}

 

์œ„์™€ ๊ฐ™์ด ์ž‘์„ฑํ•˜๋ฉด, ์•„๋ž˜์™€ ๊ฐ™์€ ์˜ค๋ฅ˜๋ฅผ ๋งˆ์ฃผ์ณค์Šต๋‹ˆ๋‹ค.

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'dataSourceScriptDatabaseInitializer' defined in class path resource [org/springframework/boot/autoconfigure/sql/init/DataSourceInitializationConfiguration.class]: Unsatisfied dependency expressed through method 'dataSourceScriptDatabaseInitializer' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource': Invocation of init method failed; nested exception is java.lang.IllegalStateException: Failed to replace DataSource with an embedded database for tests. If you want an embedded database please put a supported one on the classpath or tune the replace attribute of @AutoConfigureTestDatabase.

ํ…Œ์ŠคํŠธ๋ฅผ ์œ„ํ•œ ์ž„๋ฒ ๋””๋“œ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์— ๋Œ€ํ•œ DataSource๋ฅผ ๊ต์ฒดํ•˜๋Š”๋ฐ ์‹คํŒจํ–ˆ๋‹ค๋Š” ๋ฉ”์‹œ์ง€๋ฅผ ๋ฐœ๊ฒฌํ–ˆ์Šต๋‹ˆ๋‹ค.

์ž„๋ฒ ๋””๋“œ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋ฅผ ์„ค์ •ํ•œ ์ ์ด ์—†์ง€๋งŒ, ์ž„๋ฒ ๋””๋“œ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋ฅผ ์‚ฌ์šฉํ•˜๊ธธ ์›ํ•œ๋‹ค๋ฉด classpath์— ์ €์žฅ๋œ, ์ง€์›ํ•˜๋Š” ๊ฒƒ์„ ์‚ฌ์šฉํ•˜๊ฑฐ๋‚˜ @AutoConfigureTestDatabase ์–ด๋…ธํ…Œ์ด์…˜์˜ replace ์˜ต์…˜์„ ์กฐ์ •ํ•˜๊ธฐ๋ฅผ ๋ฐ”๋ผ๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.

 

์ด๋Ÿฌํ•œ ์˜ค๋ฅ˜๊ฐ€ ๋‚˜ํƒ€๋‚œ ์ด์œ ๋ฅผ ์‚ดํŽด๋ณด๊ธฐ ์œ„ํ•ด, @DataJpaTest ์–ด๋…ธํ…Œ์ด์…˜์„ ์‚ดํŽด๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@BootstrapWith(DataJpaTestContextBootstrapper.class)
@ExtendWith(SpringExtension.class)
@OverrideAutoConfiguration(enabled = false)
@TypeExcludeFilters(DataJpaTypeExcludeFilter.class)
@Transactional
@AutoConfigureCache
@AutoConfigureDataJpa
@AutoConfigureTestDatabase
@AutoConfigureTestEntityManager
@ImportAutoConfiguration
public @interface DataJpaTest {
}

 

๊ธฐ๋ณธ์ ์œผ๋กœ, @DataJpaTest์—๋Š” @AutoConfigureTestDatabase๋ผ๋Š” ์–ด๋…ธํ…Œ์ด์…˜์ด ๋‹ฌ๋ ค์žˆ์Šต๋‹ˆ๋‹ค.

๊ทธ๋ž˜์„œ ์œ„์™€ ๊ฐ™์€ ์—๋Ÿฌ๋ฉ”์‹œ์ง€๊ฐ€, @DataJpaTest ์–ด๋…ธํ…Œ์ด์…˜ ๋‚ด๋ถ€ ๋กœ์ง์„ ์ฒ˜๋ฆฌํ•˜๋ฉด์„œ ๋ฐœ์ƒํ–ˆ๋‹ค๋Š” ์‚ฌ์‹ค์„ ์•Œ๊ฒŒ ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.

 

@Target({ ElementType.TYPE, ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@ImportAutoConfiguration
@PropertyMapping("spring.test.database")
public @interface AutoConfigureTestDatabase {

	/**
	 * Determines what type of existing DataSource bean can be replaced.
	 * @return the type of existing DataSource to replace
	 */
	@PropertyMapping(skip = SkipPropertyMapping.ON_DEFAULT_VALUE)
	Replace replace() default Replace.ANY;

	/**
	 * The type of connection to be established when {@link #replace() replacing} the
	 * DataSource. By default will attempt to detect the connection based on the
	 * classpath.
	 * @return the type of connection to use
	 */
	EmbeddedDatabaseConnection connection() default EmbeddedDatabaseConnection.NONE;

	/**
	 * What the test database can replace.
	 */
	enum Replace {

		/**
		 * Replace the DataSource bean whether it was auto-configured or manually defined.
		 */
		ANY,

		/**
		 * Only replace the DataSource if it was auto-configured.
		 */
		AUTO_CONFIGURED,

		/**
		 * Don't replace the application default DataSource.
		 */
		NONE

	}

}

 

๋‚ด๋ถ€๋ฅผ ์‚ดํŽด๋ด…์‹œ๋‹ค. ์—๋Ÿฌ ๋ฉ”์‹œ์ง€์—์„œ replace attribute๋ฅผ ์กฐ์ •ํ•˜๋ผ๊ณ  ํ•˜์˜€์œผ๋ฏ€๋กœ, replace๋ฅผ ๋จผ์ € ํ™•์ธํ•ด๋ด…์‹œ๋‹ค. @AutoConfigureTestDatabase์˜ replace์˜ default๊ฐ’์€ Replace.ANY;์— ํ•ด๋‹นํ•ฉ๋‹ˆ๋‹ค. 

replace๋Š” ์•„๋ž˜์˜ EmbeddedDatabase์— ๊ด€ํ•œ ์„ค์ •์„ ๊ฒฐ์ •ํ•ฉ๋‹ˆ๋‹ค.

ANY → ์ž๋™ ๊ตฌ์„ฑ๋˜์—ˆ๋“ , ์ˆ˜๋™์œผ๋กœ ์ •์˜ํ–ˆ๋“  ์ƒ๊ด€์—†์ด DataSource ๋นˆ์„ ๊ต์ฒดํ•˜๋Š” Enum ๊ฐ’
AUTO_CONFIGURED → ์ž๋™ ๊ตฌ์„ฑ๋œ ๊ฒฝ์šฐ์—๋งŒ DataSource ๋นˆ ๊ต์ฒดํ•˜๋Š” Enum ๊ฐ’
NONE → DataSource๋ฅผ ๊ต์ฒด ํ•˜์ง€ ์•Š์Œ

๋”ฐ๋ผ์„œ, ์ง€๊ธˆ ์ƒํƒœ๋กœ๋Š” ํ…Œ์ŠคํŠธ๋ฅผ ์œ„ํ•œ DataSource ๋นˆ์ด ๊ต์ฒด๋œ๋‹ค๋Š” ์‚ฌ์‹ค์„ ์•Œ๊ฒŒ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.

 

EmbeddedDatabaseConnection์€ default ๊ฐ’์œผ๋กœ EmbeddedDatabaseConnection.NONE;์„ ๊ฐ–์Šต๋‹ˆ๋‹ค.

EmbeddedDatabaseConnection์€, H2, DERBY, HSQLDB ๋“ฑ์„ ์ง€์›ํ•ฉ๋‹ˆ๋‹ค.

public enum EmbeddedDatabaseConnection {

	/**
	 * No Connection.
	 */
	NONE(null, null, null, (url) -> false),

	/**
	 * H2 Database Connection.
	 */
	H2(EmbeddedDatabaseType.H2, DatabaseDriver.H2.getDriverClassName(),
			"jdbc:h2:mem:%s;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE", (url) -> url.contains(":h2:mem")),

	/**
	 * Derby Database Connection.
	 */
	DERBY(EmbeddedDatabaseType.DERBY, DatabaseDriver.DERBY.getDriverClassName(), "jdbc:derby:memory:%s;create=true",
			(url) -> true),

	/**
	 * HSQL Database Connection.
	 * @since 2.4.0
	 */
	HSQLDB(EmbeddedDatabaseType.HSQL, DatabaseDriver.HSQLDB.getDriverClassName(), "org.hsqldb.jdbcDriver",
			"jdbc:hsqldb:mem:%s", (url) -> url.contains(":hsqldb:mem:"));
  }

 

๊ทธ ์ค‘, default๋กœ None์„ ๊ฐ€์ง€๋ฏ€๋กœ,

private final EmbeddedDatabaseType type;

private final String driverClass;

private final String alternativeDriverClass;

private final String url;

์˜ ๊ฐ’์€ ๋ชจ๋‘ null์ธ Enum๊ฐ’์ด ์„ ํƒ๋˜์—ˆ๋„ค์š”.

 

@AutoConfigureTestDatabase์˜ ์ฃผ์„์„ ์‚ดํŽด๋ณด๋ฉด, TestDatabaseAutoConfiguration์— See Also๊ฐ€ ๋˜์–ด์žˆ๋Š” ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ ํ™•์ธํ•ด๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

 

@Configuration(proxyBeanMethods = false)
@AutoConfigureBefore(DataSourceAutoConfiguration.class)
public class TestDatabaseAutoConfiguration {

	@Bean
	@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
	@ConditionalOnProperty(prefix = "spring.test.database", name = "replace", havingValue = "ANY",
			matchIfMissing = true)
	static EmbeddedDataSourceBeanFactoryPostProcessor embeddedDataSourceBeanFactoryPostProcessor() {
		return new EmbeddedDataSourceBeanFactoryPostProcessor();
	}

}

TestDatabaseAutoConfiguration์€ ํ…Œ์ŠคํŠธ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋ฅผ ์œ„ํ•œ Auto-configuration์ด๋ผ๊ณ  ํ•ฉ๋‹ˆ๋‹ค.

๊ทธ ์ค‘, @ConditionalOnProperty ์–ด๋…ธํ…Œ์ด์…˜์—์„œ replace ๊ฐ’์— ๋Œ€ํ•˜์—ฌ ANY ๊ฐ’์„ ๊ฐ–๋Š”๋‹ค๋ฉด ์ƒˆ๋กœ์šด EmbeddedDataSourceBeanFactoryPostProcessor๋ฅผ ๋™์ ํ• ๋‹นํ•ด์„œ ๋นˆ์œผ๋กœ ๋“ฑ๋กํ•˜๋Š” ๋ชจ์Šต์„ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

EmbeddedDataSourceBeanFactoryPostProcessor๋Š” BeanDefinitionRegistryPostProcessor๋ฅผ ๊ตฌํ˜„ํ•˜๊ณ  ์žˆ๊ณ ,

์ด ์ธํ„ฐํŽ˜์ด์Šค์— ๋Œ€ํ•œ ์„ค๋ช…์€ ์•„๋ž˜์˜ ๋งํฌ์—์„œ ํ™•์ธํ•  ์ˆ˜ ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค

 

BeanDefinitionRegistryPostProcessor์˜ ์‚ฌ์šฉ

Spring์—์„œ ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์ด ์‹œ์ž‘๋  ๋•Œ ๋™์ ์œผ๋กœ Bean์„ ์ƒ์„ฑํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ๋‹ค์–‘ํ•œ ๋ฐฉ๋ฒ•์ด ์กด์žฌํ•œ๋‹ค. ์•ž์„œ์—๋Š” Application Context ์˜ Event Listener๋ฅผ ํ†ตํ•ด ๋™์  Bean์„ ์ƒ์„ฑํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์†Œ๊ฐœํ•œ ์ ์ด ์žˆ๋Š”๋ฐ

ysjee141.github.io

 

postProcessBeanDefinitionRegistry๋ฅผ ์˜ค๋ฒ„๋ผ์ด๋”ฉํ•ด์„œ BeanFactory๋ฅผ ํ†ตํ•ด์„œ ๋นˆ ์ •๋ณด๋ฅผ ๋“ฑ๋ก์‹œํ‚ฌ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

process(registry, (ConfigurableListableBeanFactory) registry);

์œ„์™€ ๊ฐ™์ด ํ•ด๋‹น ๋ฉ”์†Œ๋“œ์—์„œ EmbeddedDataSourceBeanFactoryPostProcessor.process๋ฅผ ํ˜ธ์ถœํ•˜๊ณ ,

 

registry.registerBeanDefinition(beanName, createEmbeddedBeanDefinition(primary));

process ๋ฉ”์†Œ๋“œ์—์„œ๋Š” createEmbeddedBeanDefinition์„ ํ˜ธ์ถœํ•ฉ๋‹ˆ๋‹ค.

 

createEmbeddedBeanDefinition์—์„œ RootBeanDefinition์„ ์„ค์ •ํ•˜๋ฉด์„œ

EmbeddedDataSourceFactoryBean.class

๋ฅผ ํŒŒ๋ผ๋ฏธํ„ฐ๋กœ ๋„ฃ์Šต๋‹ˆ๋‹ค.

 

EmbeddedDataSourceFactoryBean์€ InitializingBean์„ ๊ตฌํ˜„ํ•˜๊ณ  ์žˆ๊ณ , afterPropertiesSet์„ ์˜ค๋ฒ„๋ผ์ด๋”ฉ ํ•จ์œผ๋กœ์จ BeanFactory์— ์˜ํ•ด ๋ชจ๋“  property ๊ฐ€ ์„ค์ •๋˜๊ณ  ๋‚œ ๋’ค ํ•ด๋‹น ๋ฉ”์†Œ๋“œ๊ฐ€ ์‹คํ–‰๋ฉ๋‹ˆ๋‹ค.

 

ํ•ด๋‹น ๋ฉ”์†Œ๋“œ์—์„œ๋Š” 

@Override
public void afterPropertiesSet() throws Exception {
   this.embeddedDatabase = this.factory.getEmbeddedDatabase();
}

์™€ ๊ฐ™์ด getEmbeddedDatabase ๋ฉ”์†Œ๋“œ๋ฅผ ํ˜ธ์ถœํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.

 

๋งˆ์นจ๋‚ด, ์˜ค๋ฅ˜์—์„œ ๋ฐœ๊ฒฌํ•œ ๋ฌธ๊ตฌ๊ฐ€ ๋ณด์ด๊ธฐ ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค.

EmbeddedDatabase getEmbeddedDatabase() {
   EmbeddedDatabaseConnection connection = this.environment.getProperty("spring.test.database.connection",
         EmbeddedDatabaseConnection.class, EmbeddedDatabaseConnection.NONE);
   if (EmbeddedDatabaseConnection.NONE.equals(connection)) {
      connection = EmbeddedDatabaseConnection.get(getClass().getClassLoader());
   }
   Assert.state(connection != EmbeddedDatabaseConnection.NONE,
         "Failed to replace DataSource with an embedded database for tests. If "
               + "you want an embedded database please put a supported one "
               + "on the classpath or tune the replace attribute of @AutoConfigureTestDatabase.");
   return new EmbeddedDatabaseBuilder().generateUniqueName(true).setType(connection.getType()).build();
}

Assert.state์—์„œ EmbeddedDatabaseConnection.NONE์ด ์•„๋‹˜์„ ๋ณด์žฅํ•˜๊ณ  ์žˆ์œผ๋‚˜,

์œ„์—์„œ ๋ดค๋“ฏ์ด, EmbeddedDatabaseConnection ๊ฐ’์€ EmbeddedDatabaseConnection.NONE์œผ๋กœ ์„ค์ •๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ ์ด ๋ถ€๋ถ„์—์„œ ์—๋Ÿฌ๊ฐ€ ๋‚œ ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค.

 

๋”ฐ๋ผ์„œ ์ด ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•˜๊ณ , ํ…Œ์ŠคํŠธ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๊ฐ€ ์•„๋‹Œ ์‹ค์ œ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋ฅผ ์‚ฌ์šฉํ•˜๊ณ ์ž ํ•œ๋‹ค๋ฉด,

@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)

๊ณผ ๊ฐ™์ด replace ๊ฐ’์„ NONE์œผ๋กœ ๋ณ€๊ฒฝํ•ด์ฃผ๋ฉด ๋ฉ๋‹ˆ๋‹ค. ANY๊ฐ€ Default ์˜€๊ธฐ ๋•Œ๋ฌธ์— ๋ฐœ์ƒํ•œ ๋ฌธ์ œ์ž„์„ ์•Œ ์ˆ˜ ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค.

 

@DataJpaTest
@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)
class GTMemberEntityTest{

    @Autowired
    private GTAccountInfoRepository accountInfoRepository;

    @Autowired
    private GTMemberInfoRepository memberInfoRepository;

    @Autowired
    private GTAccountUserRoleInfoRepository accountUserRoleInfoRepository;

    @Test
    @DisplayName("๐Ÿค” 1. ๊ณ„์ •์ •๋ณด ์ƒ์„ฑ ๋ฐ ์ €์žฅ ํ…Œ์ŠคํŠธ : ์„ฑ๊ณต ์ผ€์ด์Šค")
    @Transactional
    public void testForCreateNewAccountInfoAndSave(){
        GTAccountInfo mockAccountInfo = GTAccountInfo.builder()
                .accountEmail("test@example.com")
                .accountPW("1234")
                .build();

        GTAccountInfo savedAccountInfo = accountInfoRepository.save(mockAccountInfo);

        assertEquals(savedAccountInfo.getAccountEmail(), "test@example.com");
        assertEquals(savedAccountInfo.getAccountPW(), "1234");
        assertEquals(savedAccountInfo.getRoles().size(), 0);

    }
    
}

 

 

 

Spring Bean์ด ์–ด๋–ป๊ฒŒ ๋“ฑ๋ก๋˜๋Š”์ง€ ์ •ํ™•ํ•œ ๊ณผ์ •์„ ์ž˜ ๋ชฐ๋ž๊ธฐ์— ๋Œ€๋žต์ ์œผ๋กœ๋ฐ–์— ๋ฌธ์ œ์˜ ์›์ธ์„ ํŒŒ์•…ํ•˜์ง€ ๋ชปํ–ˆ์Šต๋‹ˆ๋‹ค.

๋‚˜์ค‘์— ์ถ”๊ฐ€์ ์ธ ํ•™์Šต์„ ํ†ตํ•ด์„œ Spring Bean์ด ์–ด๋–ป๊ฒŒ ๋“ฑ๋ก๋˜๋Š”์ง€ ์ž์„ธํžˆ ๊ณต๋ถ€ํ•  ํ•„์š”์„ฑ์„ ๋А๊ผˆ์Šต๋‹ˆ๋‹ค. 

์ €์ž‘์žํ‘œ์‹œ ๋น„์˜๋ฆฌ ๋™์ผ์กฐ๊ฑด (์ƒˆ์ฐฝ์—ด๋ฆผ)

'๐Ÿƒโ€โ™‚๏ธ DEVLOG' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

[DEVLOG] @Builder์™€ @Builder.Default  (0) 2023.04.12
[DEVLOG] if(kakao) dev 2022 ๊ฐœ๋ฐœ์ž ์ปจํผ๋Ÿฐ์Šค ํ›„๊ธฐ - 1. ISFP์˜ ์ฝ”๋“œ ๊ฐ€๋…์„ฑ ๊ฐœ์„  ๊ฒฝํ—˜  (1) 2023.01.01
[DEVLOG] ์šฐ๋‹นํƒ•ํƒ• ์ œ๋ฐœ๋ชจ๋ฐœ v2 ๊ฐœ๋ฐœ๊ธฐ - ํƒˆ๋ชจ ์ง„๋‹จ API ์ˆ˜์ •ํ•˜๊ธฐ (4) createdAt๊ณผ updatedAt, JPA AttributeConverter  (1) 2022.12.27
[DEVLOG] ์šฐ๋‹นํƒ•ํƒ• ์ œ๋ฐœ๋ชจ๋ฐœ v2 ๊ฐœ๋ฐœ๊ธฐ - ํƒˆ๋ชจ ์ง„๋‹จ API ์ˆ˜์ •ํ•˜๊ธฐ (3) DTO์— ๋”ฐ๋ฅธ ์‘๋‹ต ์ƒ์„ฑ ํด๋ž˜์Šค ๋งŒ๋“ค๊ธฐ  (0) 2022.12.16
[DEVLOG] ์šฐ๋‹นํƒ•ํƒ• ์ œ๋ฐœ๋ชจ๋ฐœ v2 ๊ฐœ๋ฐœ๊ธฐ - ํƒˆ๋ชจ ์ง„๋‹จ API ์ˆ˜์ •ํ•˜๊ธฐ (2) ๊ณตํ†ตํ•„๋“œ๊ฐ€ ๋งŽ์€ DTO ๋งŒ๋“ค๊ธฐ  (0) 2022.12.16
    '๐Ÿƒ‍โ™‚๏ธ DEVLOG' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€
    • [DEVLOG] @Builder์™€ @Builder.Default
    • [DEVLOG] if(kakao) dev 2022 ๊ฐœ๋ฐœ์ž ์ปจํผ๋Ÿฐ์Šค ํ›„๊ธฐ - 1. ISFP์˜ ์ฝ”๋“œ ๊ฐ€๋…์„ฑ ๊ฐœ์„  ๊ฒฝํ—˜
    • [DEVLOG] ์šฐ๋‹นํƒ•ํƒ• ์ œ๋ฐœ๋ชจ๋ฐœ v2 ๊ฐœ๋ฐœ๊ธฐ - ํƒˆ๋ชจ ์ง„๋‹จ API ์ˆ˜์ •ํ•˜๊ธฐ (4) createdAt๊ณผ updatedAt, JPA AttributeConverter
    • [DEVLOG] ์šฐ๋‹นํƒ•ํƒ• ์ œ๋ฐœ๋ชจ๋ฐœ v2 ๊ฐœ๋ฐœ๊ธฐ - ํƒˆ๋ชจ ์ง„๋‹จ API ์ˆ˜์ •ํ•˜๊ธฐ (3) DTO์— ๋”ฐ๋ฅธ ์‘๋‹ต ์ƒ์„ฑ ํด๋ž˜์Šค ๋งŒ๋“ค๊ธฐ
    ๊ฐœ๋ฐœ์ž HOON
    ๊ฐœ๋ฐœ์ž HOON
    ์ข‹์€ ๋ฐฑ์—”๋“œ ์—”์ง€๋‹ˆ์–ด๊ฐ€ ๋˜๊ธฐ ์œ„ํ•œ ๊ธฐ๋ก์„ ๋ชจ์•˜์Šต๋‹ˆ๋‹ค. # ์ฃผ๋‹ˆ์–ด # ๋ฐฑ์—”๋“œ # ๊ฐœ๋ฐœ์ž

    ํ‹ฐ์Šคํ† ๋ฆฌํˆด๋ฐ”